How to get list of registered custom elements

前端 未结 7 528
萌比男神i
萌比男神i 2020-12-08 09:55

I\'m trying to detect whether a custom element with a specific name was registered or not. Is there a way to make such check?

Or is there a way to get list of regist

相关标签:
7条回答
  • 2020-12-08 10:36

    There doesn't seem to a way to see all registered elements at the moment, but there is a way to check whether or not an element has been registered already: wrap the register in a try...catch block:

    try {
        document.registerElement('x-my-element');
    } catch(e) {
        console.log('already exists', e);
    }
    

    Run this twice in your console and you'll see the error logged.

    This does have a drawback if you simply want to check whether or not it was registered though: if it was not, it will be after running this. There also isn't a way to unregister an element it seems.

    0 讨论(0)
提交回复
热议问题