I want MutationObserver to see changes via innerHTML

Submitted by Christian "Schepp" Schaefer

MutationObserver is great. I use it, together with Node.matches(), to initialize components; DOMContentLoaded is now a thing of the past. It doesn't matter when or how new content gets inserted into a document, MutationObserver is gonna be there, handling any post-processing. Now, as nice as this sounds, there is one thing that really sucks about MutationObserver: it will not fire for nodes that are being inserted/created via innerHTML; only the outermost mutation will be seen and fire the event. This means that everytime MutationObserver fires, we have to query for nodes inside the target node and we need to track its children so we can then initialize all the new ones. Here’s an example; it’s super cumbersome! Updating MutationObserver with the ability to see nodes inserted via innerHTML would help considerably.

Tagged
JavaScript