Reputation: 4004
I have a random DOM node and I want to determine whether it is an svg
element, namely that is inherits from the SVGElement
constructor. I know I could just walk up the prototype chain by calling __proto__
on the node, but is there a built in method to determine this?
Upvotes: 4
Views: 267
Reputation: 154868
There is the dedicated instanceof
operator which checks whether an object has a constructor's prototype in its prototype chain:
node instanceof SVGElement
However, given that you cannot actually do new SVGElement()
(as with all node constructors), this may not work reliably across all browsers.
Upvotes: 1