Created
August 26, 2021 12:41
-
-
Save ihorduchenko/2839b2eae7435892881a9806ae13f598 to your computer and use it in GitHub Desktop.
Use mutation observer to detect dynamic element creation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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