Reputation: 6911
ParentNode interface declares property firstElementChild. I have seen people using children[0] everywhere, so it makes me wonder, is there a difference between using firstElementChild
and children[0]
?
Upvotes: 2
Views: 2535
Reputation: 1210
children[0]
will produce the same result as firstElementChild
. Will firstElementChild returns the first child node as an element node (ignores text and comment nodes). The children
property is fully supported in IE6 to IE8. However, in these versions, it returns element nodes AND comment nodes. IE9+ returns only element nodes.
Source: W3C
Keep rocking!
Upvotes: 2