I have the following HTML data on a website which I am trying to manipulate using an extension in Google Chrome:
<div id="lvl-2">
<div class="loading" style="display: none;"><div class="loading-text"><div class="nowloading">Loading…</div>
<div class="content">
<div class="dirs">
<form class="search">
<input type="text">
</form>
<div class="dirs-list"></div>
</div> <!-- dirs -->
<div class="tunes"><table>
<tbody>
<tr></tr>
...
<tr></tr>
</tbody></table>
</div>
</div>
I am using the following code to get the table element somehow:
var div1 = document.getElementById("lvl-2");
var divChild1 = div1.children;
var divChild2 = divChild1[1].children;
var tables = divChild2[1].children;
But on executing the line where the tables variable is assigned, I am getting this error:
Cannot read property 'children' of undefined.
I am not sure why am I getting this error, as second child of the divChild2 variable should contain the table as a child. What do you suggest I should do? Ultimately, my aim is to randomize all the rows in the table. If there is another way I can do that, I would welcome it.
P.S. 1: I am a Javascript noob, I think it is abundantly clear.
P.S. 2: Apologies for the weird HTML. I had to remove a lot of useless tags in between the relevant tags. Otherwise the HTML would have gotten huge.