Skip to content

Instantly share code, notes, and snippets.

@ihorduchenko
Created August 26, 2021 12:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ihorduchenko/2839b2eae7435892881a9806ae13f598 to your computer and use it in GitHub Desktop.
Save ihorduchenko/2839b2eae7435892881a9806ae13f598 to your computer and use it in GitHub Desktop.
Use mutation observer to detect dynamic element creation
var target = document.querySelector('#bc-sf-filter-products');
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.type === 'childList') {
// Do some stuff
productsGrid();
}
});
});
var config = { attributes: true, childList: true, characterData: true }
if (target.length) {
observer.observe(target, config);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment