Is there a javascript way of determining if an object implements the 'HTMLAnchorElement' interface? When I do typeOf(someVariable) it returns 'object'. Can I take that a step further and verify the type implements the 'HTMLAnchorElement' interface? Seems like it would be simple enough but I can't find any examples. Any help or sample code would be appreciated. Thanks!
You can use the instanceof operator.
Example:
var a = document.links[0];
alert(a instanceof HTMLAnchorElement); // true if there's a link in the document
Note that IE7- doesn't define the HTMLAnchorElement object. As a fallback, you can check for the tagName or nodeName property of a supposed element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With