Feature test support for HTML elements currently defined in the specification as well as custom elements registered via
document.registerElement. Please refer to the blog post to read more, or see a working example.
It works by looking at an element's constructor to see which interface it inherits from. Unsupported elements should derive from the
HTMLUnknownElement interface, revealing their lack of native support. Custom elements not registered via
document.registerElement should derive from the
HTMLElement interface or the
HTMLUnknownElement interface if an invalid tag name is used.
To use the method, simply provide a string of an HTML tag name:
// Feature test the dialog element isElementSupported('dialog'); // Feature test the template element isElementSupported('template'); // Feature test custom elements isElementSupported('custom-element'); // false document.registerElement('custom-element'); isElementSupported('custom-element'); // true
The function will return true for natively supported elements as well as registered custom elements, false for unsupported elements and unregistered custom elements, and undefined for browsers that do not support the
- Chrome *
- Firefox *
- Opera *
- Safari *
- Internet Explorer 9+
- Android *
- iOS *
This project is dedicated to the public domain as described by the Unlicense.