FireFox doesn't understand a DOM node-tree?
<
div id="div1"><div id="div2" onclick="alert(this.parentNode.childNodes[0].id)">clickme</div>
</div>
I've tested this HTML snippet on both IE and FireFox, and guess what?
IE reacts as expected by alerting "div2".
However, FireFox alerts "undefined"....?
Apparently, in FireFox div2 is considered to be the second childNode of div1; not the first. I guess this is because FireFox parses the whitespace between div1 and div2 as being a seperate node! BUT WHY????
Did the creators of FireFox (Mozilla Foundation) implemented this by design? Is it ever going to be fixed in FireFox? Or do we just have to live with it, and write seperate javascript for IE and FireFox?
[Note: of course I can let IE and FF return the same results by removing all whitespace between the div1 and div2 tags, but that would result in human-unreadable and hard to maintain Html.]
Postscript:
I've received a lot of comments about the fact that FireFox precisely (I'd say 'rigidly') follows the w3c DOM recommendation on this. I'm aware of the w3c specs, but I still think it sucks having to write seperate code for IE and FF (or include a library of wrapper functions).
Personally, I think the IE dom-representation is the more sensible one, whether it's in the recommendation or not.
And FireFox just made a very bad 'first impression' to me :(
Read these links on more information why Mozilla has chosen to preserve whitespaces in the DOM:
- https://bugzilla.mozilla.org/show_bug.cgi?id=26179 (the 'whitespace' bug with a lengthy discussion)
- http://www.mozilla.org/docs/dom/technote/whitespace/ (Mozilla explaining the issue and giving a poor solution)