you’re on your way �
237
the document object model
Some browsers don’t recognize Node
Unfortunately, some web browsers don’t support the Node
class in your JavaScript. Your code won’t run, and you’re back
to dealing with errors and null values.
if (someNode.nodeType == Node.ELEMENT_NODE) {
// Do something with the element node
} else if (someNode.nodeType == Node.TEXT_NODE) {
// Do something with the text node
}
All browsers support the
nodeType proeprty...
...but several browsers report an
error right here.
Here’s IE reporting
that it doesn’t
recognize the Node
object in your code.
Q:
So as long as my users aren’t running Internet
Explorer, I can use the Node object, right?
A: Actually, you shouldn’t ever use the Node object... at least
not until all major browsers support the Node object. Even if you
don’t think your users are running IE, it’s still the world’s most
popular browser (by a long-shot). In the next chapter, you’’ll see
that you can get the same results with a little more work, and end
up with code that works on all browsers.
questions
Frequently asked
?