Skip to content

Instantly share code, notes, and snippets.

@dantaeyoung
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dantaeyoung/14424d254d86ff16ea48 to your computer and use it in GitHub Desktop.
Save dantaeyoung/14424d254d86ff16ea48 to your computer and use it in GitHub Desktop.
HTML DOM listener
(function() {
// Load jQuery
var script = document.createElement("SCRIPT");
script.src = 'https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js';
script.type = 'text/javascript';
document.getElementsByTagName("head")[0].appendChild(script);
// Poll for jQuery to come into existance
var checkReady = function(callback) {
if (window.jQuery) {
callback(jQuery);
}
else {
window.setTimeout(function() { checkReady(callback); }, 100);
}
};
// Start polling...
checkReady(function($) {
$("<style type='text/css'> .watch-element { border: 2px solid red;} </style>").appendTo("head");
var watchElement;
$(document).click(function(event) {
if(watchElement === undefined) {
watchElement = $(event.target);
watchElement.addClass("watch-element");
watchElement.bind("DOMSubtreeModified",function() {
console.log(watchElement.html());
});
}
});
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment