Reputation: 45484
Is there a way to detect when a shadow root is removed from an element without polling? I would like to know if it is possible to do this in both v0 and v1 APIs. When in v1 API, it should work even if the root is closed.
Upvotes: 2
Views: 540
Reputation: 31191
The Shadow DOM can't be detached or replaced but its content can be removed.
You can set a MutationObserver
on its shadowRoot
to detect that:
var target= element.shadowRoot
var observer = new MutationObserver( callback )
observer.observe( target, { subtree: true, childList: true } )
Upvotes: 0
Reputation: 45484
Apparently (correct me if wrong), once an element has a shadow root, it will always have a shadow root. So, therefore this question is invalid because an element that has a shadow root must continue always having a shadow root.
Upvotes: 1