How to check if a DOM node inherits from a constructor?

I have a random DOM node, and I want to determine if it is an svg element, namely it inherits from the SVGElement constructor. I know that I can just go up to the prototype chain by calling __proto__ on node, but is there a built-in method to determine this?

+4
source share
1 answer

There is a dedicated instanceof statement that checks if an object has a constructor prototype in the prototype chain:

 node instanceof SVGElement 

However, given that you really cannot do new SVGElement() (as with all node constructors), this may not work reliably in all browsers.

+1
source

Source: https://habr.com/ru/post/1432132/


All Articles