I wish to check if an argument passed to my function is an HTMLElement, using the instanceof operator. I know that this doesn’t work in IE7, because AFAIK IE7 doesn’t define HTMLElement. I figured: no problem, I’ll just fall back to a parent prototype like Node. But, as answers on StackOverflow have learned me, the Node-object is also not defined in IE7
What now is the best way to test if my parameter is a node/HTMLElement? Am I doing it wrong?
In the Node interface
HTMLElementcorresponds to nodes of type 1.http://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-1841493061
Thus, you should check for the argument’s
nodeType: