dom - javascript check if object implements HTMLAnchorElement interface - Stack Overflow

Is there a javascript way of determining if an object implements the 'HTMLAnchorElement' inte

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!

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!

Share Improve this question edited Jun 10, 2012 at 13:07 TazGPL 3,7462 gold badges41 silver badges60 bronze badges asked Feb 14, 2012 at 20:04 HcabnettekHcabnettek 12.9k38 gold badges129 silver badges192 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744798429a4594344.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信