Javascript nodeType
March 24th, 2009
have you ever looped through your page to grap inputs to post somewhere? If you have, then surely you have used something like:
for (var i=0;i<elem.childNodes.length;i++)
if so, then you might have run into a little issue in which some browsers (including firefox) will render the “n” as a childNode (this is correct actually, just frustrating).
In comes the solution ….. Node.nodeType. You can check elem.childNodes[i].nodeType to see what it is (https://developer.mozilla.org/En/DOM/Node.nodeType). If it is a 1, it is an element (li, div, etc). skip everything that is != 1, and tada! You are in business!
hope this helps someone