Vote count:
0
I am having difficulty using the Mutation Observers and disconnecting on callback.
var observer = new MutationObserver(function(mutations) {
mutations.forEach(function(mutation) {
if (mutation.addedNodes)
{
var element = getElement(selectors);
if(element)
{
observer.disconnect();
return callback(element);
}
}
})
});
observer.observe(document.body, {
childList: true,
subtree: true,
attributes: false,
characterData: false
});
observer.disconnect() is not stopping the listener, if I put it after the observer.observe then it will work but then I effectively a, not doing anything because it stops listening right away.
How do you disconnect inside the callback?
asked 37 secs ago
disconnecting from Mutation Observers
Aucun commentaire:
Enregistrer un commentaire