I’m trying to write javascript to find page elements relative to a given element by using parentNode, firstChild, nextSibling, childNodes[], and so on. Firefox messes this up by inserting text nodes between each html element. I’ve read that I can defeat this by removing all whitespace between elements but I’ve tried that and it doesn’t doesn’t work. Is there a way to write code that works on all modern browsers?
For example:
<div id='parent'><p id='child'>Hello world</p></div>
In IE parent.firstChild is child but in Firefix it’s a phantom Text element.
I have a workaround. You can insert the two methods below:
and you can now use:
instead of: