Is there a cross-browser and cross-frame way to check if an object is an HTML element?

Viewed 680

Given an object obj, I would like to check if that object is a native HTML element. I could do:

if ( obj instanceof HTMLElement )

but that doesn't work across frames (e.g. on objects from an <iframe>) since each frame has its own HTMLElement constructor. Alternatively, I could just do:

if ( obj.tagName ) 

but that's not safe/reliable, as such a property could be (un)intentionally added to the object.

So, is there a reliable way to do this?

4 Answers
Related