I've created a native Web Component (HTMLElement) and I am using it to expose an otherwise existing component (lowercase 'c') that is a fragment comprised of HTML/CSS/JS ... basically wrapping it in Web Component to help with its re-use and isolate it from the rest of a Web page.
The problem is the component i'm including in my Web Component has some JavaScript to lazy load images, and it lists for the DOMContentLoaded
document event to trigger some of its JS which manipulates the DOM (injects the proper <img>
tag) ..
I am able to get everything into my Web Component, and execute the component's JS within the shadowRoot
(with mode: open
) however the component's event listeners on DOMContentLoaded
are never invoked.
I tried writing everything in my Web Component in both the constructor()
as well as connectedCallback()
but they acted the same.
- Does a Web Component/ShadowDOM have its own DOMContentLoaded event? And/or does it respect the parent DOM's "state"?
- If I execute JS in the context of the Web Component that binds an event listener for
document...
does that event listener apply only to the ShadowDOM? Or is that actually being bound to parent DOM?
UPDATE: I am loading my Web Component asychronously - so it's loaded after the parent's natural DOMContentLoaded event triggers.