Mutation Observer for creating new elements

This is code that listens for mutations on the childlist of #foo and checks to see if a child with the id of bar is added. MutationObserver = window.MutationObserver || window.WebKitMutationObserver; $(“#foo”).live(“click”,function(e) { e.preventDefault(); $(this).append($(“<div />”).html(“new div”).attr(“id”,”bar”)); }); // define a new observer var obs = new MutationObserver(function(mutations, observer) { // look through all mutations … Read more

When are MutationObserver callbacks fired?

MutationObservers are fired asynchronously but ‘soon’, which means they fire before other things in the queue, such as layout, paint, or triggered events. This ameliorates the loss of synchrony, because you don’t have to worry about screen flashing or other bad things happening before your observer gets a chance to react. In developer notes, they … Read more

tech