i have:
<td id="td1">
<div>
aaaaaa
</div>
</td>
how can i get the innerHTML of the child of "td1" ?
function displaymessage() {
var i = 0;
alert(document.getElementById("td1").childNodes[0].innerHTML);
}
dosen't work.
few browser considered whitespace as text node and that create a problem while traversing.
to avoid that you should check the node type
see more information here
Some browsers interpret a line break as the first
childNode
. So you can do:or a safer method
[edit 2019] or more modern
I hate to be the guy that uses jQuery to solve every DOM selection/manipulation problem, but if you used jQuery all you would need is...
try with alert(document.getElementById("td1").childNodes[1].innerHTML);