I have this simple example
<table border="1px"> <tr> <td> </td> <td> <input type="button" value="Click" onclick="insertText()"/> </td> </tr> </table>
I wanted to get the first td element of the (first) tr element, I tried:
var td = document.getElementsByTagName("table")[0].children[0].children[0];
Because it:
var td = document.getElementsByTagName("table")[0] for the table element itselfchildren[0] for the tr element- and
children[0] again for the first td element
This is what I thought, but apparently it returns me a tr element and adds another .children[0] , I got a td element.
var td = document.getElementsByTagName("table")[0].children[0].children[0].children[0];
Why is this, or what did I miss here?
source share