Reputation: 731
I include a 3rd party javascript, which in turn appends child elements to a DOM and the time taken to do this is variable, is there a way for me to find out when the Mutation is complete e.g. DOMNodeInserted is complete?
My code at the moment looks like
$("#searchgadget").bind("DOMNodeInserted",function(){
alert("added");}
As expected I get alerts for every 500+ elements that are being added to the "searchgadget", however, I am only interested when this finishes I just want to do some logic after the last DOMNodeInserted. Anyways to do that?
Upvotes: 1
Views: 244
Reputation: 781058
Assuming the code that's appending nodes is running synchronously, there won't be any delay between them. You can set a timeout each time a node is inserted. When the timeout completes, it's done with all the mutations.
insertTimeout = null;
$("#searchgadget").on("DOMNodeInserted", function() {
clearTimeout(insertTimeout);
insertTimeout = setTimeout(function() {
alert("added");
}, 100);
});
Upvotes: 1