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!
1 Answer
Reset to default 8You 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条)