Skip to content

Instantly share code, notes, and snippets.

@nebuta
Created May 8, 2013 05:49
Show Gist options
  • Save nebuta/5538501 to your computer and use it in GitHub Desktop.
Save nebuta/5538501 to your computer and use it in GitHub Desktop.
MutationObserver example
function findTitle(rec){
var res = undefined;
$.each(rec,function(){
if(this.localName == 'title'){
res = this.innerText;
}
});
return res;
}
var obs = new MutationObserver(function(mutations) {
$.each(mutations,function(idx){
var t = findTitle(this.addedNodes);
if(t){
console.log(t);
}
});
}).observe(document, {
attributes: true,
childList: true,
subtree: true,
attributeFilter: ["head"]
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment