Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

javascript check if object implements HTMLAnchorElement interface

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!

like image 290
Hcabnettek Avatar asked Oct 22 '25 05:10

Hcabnettek


1 Answers

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.

like image 127
Rob W Avatar answered Oct 25 '25 04:10

Rob W



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!