this.firstElementChild should work on every significant IE browser line <= 9 and Firefox 3 ( QuirksMode ).
this.children[0] will work in all important Firefox 3 browsers, except that IE <= 9 counts comment nodes as element nodes ( QuirksMode ). This may or may not be a problem for you.
The catch-all system is as follows:
var node = this.firstChild, firstElementChild = null; for ( ; node; node = node.nextSibling) { if (node.nodeType === 1) { firstElementChild = node; break; } }
firstElementChild will be the first child, if it exists, null otherwise. It is best to check if this.firstElementChild before executing the loop for performance reasons.
lonesomeday
source share