3

The following code work in FF but not IE8:

var j = "test";
alert(j instanceof HTMLElement);

I don't think IE uses the HTMLElement object. Is there a safe way to do this check in IE? Perhaps there is a YUI solution?

2

2 Answers 2

9

I use to check the nodeType property, it should be 1 for all HTML element objects.

I used it in my crossbrowser library before I switched to jQuery.

text has a nodeType of 3 and any custom objects probably won't have a nodeType property at all.

Sign up to request clarification or add additional context in comments.

3 Comments

help.dottoro.com/ljkadgoo.php I think you got it backwards? Text is type 3, and Element is type 1?
Someone needs to correct this answer, it is backwards :) text node: 3, element node: 1, comment node: 8, etc etc. See developer.mozilla.org/en/nodeType
Fixed the numbers, sorry for getting them backwards and not noticing the first comment notice emails :/
2

If you look at the jQuery source code (not the minified one ffs!), you'll see they make use of nodeType a lot.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.