I have been working with javascript for a week now. I am currently working on making things work/change through nodes. But I have been noticing something strange, well for an unskilled javascripter it is.
I have a structure in my site like this:
<html>
<head>
<title>....</title>
<link/>
<script></script>
</head>
<body>
<div 1>
<div 2></div>
</div>
</body>
</html>
When I am trying to find a childnode with the next function:
var headerBox = document.body.childNodes;
var txt = "";
for (var x = 0; x < headerBox.length; x ++) {
txt =txt+"Childnode["+x+"]: "+headerBox[x].localName+" ("+headerBox[x].className+")<br>";
}
var x = document.getElementById(box);
x.innerHTML = txt;
I get a list with a couple of undefined "NULL" coupled with the reali DIV's
But when I simply change the "document.body.childNodes" to "document.body.children" everything comes uit perfectly, the "NULL" values even change.
What I am wondering is what does the "NULL" values represent in the HTML file, since there are no elements at where the "NULL" value is standing. In my head it is giving me a representation of something that is not there, visible, but yet it is...
Could anyone please explain to me what is going on?
Ps: I am sorry for maybe reposting this but I couldn't find a suitable other question regarding this matter!
Pss: Found a repost (What is the difference between children and childNodes in JavaScript?). But it is not answering why it still recognizes unseen childnodes as undefined.