I have been working towards understanding the DOM very thoroughly. At the moment i'm making my way trough traversing the DOM tree and i seem to be finding some inconsistencies.
- On a nodeList i can use an index to iterate trough the list
- On a HTMLElement i can't use an index
See this fiddle for an example: http://jsfiddle.net/AmhVk/4/
So the question is, why is it that the nodeList has an indexable list like element[0], element1 and the HTMLElement has not?
Could someone explain this to me very thoroughly? Thx...
<ul id="jow">
<li><a href="">Item</a></li>
<li><a href="">Item</a></li>
<li class="active"><a href="">Item</a></li>
<li class="active"><a href="">Item</a></li>
<li><a href="">Item</a></li>
<li><a href="">Item</a></li>
</ul>
<div id="ieps"></div>
function simple(){
var li = document.querySelectorAll(".active");
var ul = li[0].parentNode;
var getULchild = ul.children[0];
var ieps = document.getElementById("ieps");
ieps.innerHTML += "ul will return = " + ul + "<br>";
ieps.innerHTML += "li will return = " + li + "<br><br>";
ieps.innerHTML += "ul[0] will return: " + ul[0] + "<br>";
ieps.innerHTML += "li[0] will return: " + li[0] + "<br><br>";
}
Also, in the fiddle, if i remove 1 of the li's containg the class "active". This will still return a nodeList and not a single HTMLElement: jsfiddle.net/AmhVk/5