简体   繁体   中英

Define custom element within another custom element only

We know that we can register our custom element like this:

customElements.define('x-my-element', MyElement);

And now, this element is available like so:

<x-my-element>Woo</x-my-element>

However, is there some sort of a scoped CustomElementRegistry for a specific ShadowRoot?

I'm working on a browser plugin that needs to inject some custom elements into a page, but I want to avoid accidentally colliding with custom elements that the host page may have defined. If I define an outer custom element, and all elements within are defined to work only within that outer custom element, that solves the problem.

(As an alternative, I'll probably just randomly generate element names with a build script.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM