html - Unable to get element in javascript -


I have the following HTML data on that website, which I try to manipulate to use the extension in Google Chrome I am:

  & lt; Div id = "lvl-2" & gt; & Lt; Div class = "loading" style = "display: none;" & Gt; & Lt; Div class = "loading-text" & gt; & Lt; Div class = "abloding" & gt; Loading ... & lt; / Div & gt; & Lt; Div class = "content" & gt; & Lt; Div class = "dirs" & gt; & Lt; Form category = "search" & gt; & Lt; Input type = "text" & gt; & Lt; / Form & gt; & Lt; Div class = "dirs-list" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt ;! - dirs - & gt; & Lt; Div class = "tunes" & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; / TR & gt; ... & lt; Tr & gt; & Lt; / Tr & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

I'm using the following code to get the table element in any way:

  var div1 = document.getElementById ("lvl-2 "); Var divChild1 = div1.children; Var divChild2 = divChild1 [1]. children; Var tables = divChild2 [1]. children;  

But when executing the line, where the table variable is assigned, I am receiving this error:

  The undefined property of 'children' Can not read  

I am not sure why I am getting this error because the second child of divChild2 variable should have a table in the form of a child. What do you suggest me to do? Finally, all the rows in my target table are randomized. If there is another way I can do this, then I will welcome it.

P.S. 1: I'm javascript knob, I think it's abundantly clear.

P.S. 2: Sorry for the weird HTML, I had to remove many useless tags in the middle of the relevant tags. Otherwise HTML will earn a lot.

Your HTML is invalid, you are .loding div and some others DOM is not exactly the way you expect it to happen.

That's why all those stupid people always ask you to indent your code properly. It can be easy to catch such problems, validation is a great way to find such problems.

After running this way your HTML looks (which you can do before next time you ask a question):

  & lt; Div id = "lvl-2" & gt; & Lt; Div class = "loading" style = "display: none;" & Gt; & Lt; Div class = "loading-text" & gt; & Lt; Div class = "abloding" & gt; Loading ... & lt; / Div & gt; & Lt; Div class = "content" & gt; & Lt; Div class = "dirs" & gt; & Lt; Form category = "search" & gt; & Lt; Input type = "text" & gt; & Lt; / Form & gt; & Lt; Div class = "dirs-list" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt ;! - dirs - & gt; & Lt; Div class = "tunes" & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

Obviously this is not your hope. I've decided for you:

  & lt; Div id = "lvl-2" & gt; & Lt; Div class = "loading" style = "display: none;" & Gt; & Lt; Div class = "loading-text" & gt; & Lt; Div class = "abloding" & gt; Loading ... & lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; Div class = "content" & gt; & Lt; Div class = "dirs" & gt; & Lt; Form category = "search" & gt; & Lt; Input type = "text" & gt; & Lt; / Form & gt; & Lt; Div class = "dirs-list" & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt ;! - dirs - & gt; & Lt; Div class = "tunes" & gt; & Lt; Table & gt; & Lt; Tbody & gt; & Lt; TR & gt; & Lt; / TR & gt; & Lt; TR & gt; & Lt; / TR & gt; & Lt; / Tbody & gt; & Lt; / Table & gt; & Lt; / Div & gt; & Lt; / Div & gt; & Lt; / Div & gt;  

And with fixed HTML


Comments