Originally Posted by Kor
is not the best choice. I would have rather used:
there is a problem with data and nodeValue, stemming back to the xbrowser differences you noted: firstChild is not always a proper element.
text content is probably what the OP wants, since it grabs all the text nodes and text nodes under child elements.
the only drawback is that textContent doesn't work in IE, and it misses inputs...
but that's not a huge issue, because we can try to assign a few properties, and take only the first one that works.
href = child.value || child.innerText || child.text || child.textContent;
should work in all browsers...
node.childElementCount should be node.childNodes.length;
i see you are also using the brand new tree.children collection, which is also not included in IE.
it's like child nodes, but it skips text nodes. you can use getElmentsByTagName, or loop through childNodes and ignore the text nodes with an if statement.
to keep everything simple and concise, i like to write a few helper functions for traversing the dom.
i don't know what your level of JS is, but i can't stand using the dom without
1. coercing collections into true arrays
it makes it SOO much easier to do things cross browser when you have a reliable and consistent set of functions to do what you need to do. You can easily gather and filter collections and handle special cases without a ton of if statements.
i can whip up some examples if you like.