The OO programmer in me cringes. I ran into a bug last week in my DOM traversion code that was a bit tricky to solve. The hardest part was isolating the problem since the code had worked before some logic changes needed to be done. Once the problem was isolated I noticed that I kept getting a Text-node that wasn’t an instance of the DOM class
Text (which inherits from
CharacterData which in respect inherits from
Node) but something else (with a class of
Without going into details of why I wasn’t getting a Text-node (I confess, I didn’t have the time to figure it out, just come up with a solution), I decided to solve the issue by inspecting the class of the node that I got. If the class was empty or
Text I’d just skip it and go to the current elements parent, otherwise I’d just get the previous sibling with
previousSibling. Of course the code for this is simply:
if ((node == null) || (node instanceof Text)) // Skip... else // Do something
This worked fine in Firefox. Time to test in IE. And what do we find? IE doesn’t recognize a class
Text (or any DOM class). Searching for a solution on the Google didn’t provide any sensible answers other than the information that IE doesn’t create DOM classes are real classes but something else. So with IE you can’t try to use the simplest method to figure out the class of a node (for example in a
NodeList returned by
The OO purist in me is screaming and crying. Such elegant simplicity taken away from me by IE’s stupidity. Aargh!
P.S. Don’t ask me how I solved it. The current fix is a hack that needs to be tested better before I’ll trust it.