How To Disconnect A MutationObserver From Inside Its Callback Function?
I'm using MutationObserver to wait for the creation of an element on the page, and then adding a button on it (with init function). I only need to add one button but mutations keep
Solution 1:
Callback function in MutationObserver is called with two arguments: mutations array and observer object itself. Because of how you wrote the code detect_node_for_buttons never gets observer object. This will do the trick:
var observer = new MutationObserver(detect_node_for_buttons);
You also have to add this argument to function declaration:
function detect_node_for_buttons(mutations, observer){ ... }
Post a Comment for "How To Disconnect A MutationObserver From Inside Its Callback Function?"