The html is the traditionalCode:function FCE(e) { // {{{ /* First Child Element - only tags, not text. */ e = e.firstChild; do { e = e.nextSibling; } while (e && e.nodeType != 1); return e; } // }}} window.onload = function() { var li = document.getElementsByTagName('li'); for (var i = 0; i < li['length']; i++) { console.log(li[i]); // Outputs <li> console.log(li[i].firstChild); // Outputs <a href=...'> console.log(FCE(li[i])); // Outpus null. } };
I just can't understand what is wrong with the lineCode:<li><a href='...>text</a></li>
Why is it returning null? The two lines above do return what is supposed to be returned, and I used them just as a test.Code:console.log(FCE(li[i]));
Also, the reason why I am trying the custom FCE(e) function, is that I want to be sure that the real first child element will be returned, and not, for instance, a text node or a "white space" node.
Any help would be appreciated.


Reply With Quote

Bookmarks