Created
October 10, 2019 20:12
-
-
Save avtarnanrey/d3fbad56a2a073e357bf5ac747f68bef to your computer and use it in GitHub Desktop.
Wait for element to be added into DOM then execute JavaScript
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 observer = new MutationObserver(function (mutations) { | |
mutations.forEach(function (mutation) { | |
if (!mutation.addedNodes) return | |
for (var i = 0; i < mutation.addedNodes.length; i++) { | |
var item = Array.prototype.slice.call(mutation.addedNodes).find(function (i) { return i.id == "selector" }); | |
if (item) { | |
// Do your stuff here | |
observer.disconnect(); | |
} | |
} | |
}) | |
}) | |
observer.observe(document.querySelector("#parent_tag"), { | |
childList: true, | |
subtree: true, | |
attributes: false, | |
characterData: false | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment