Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript: Check if Element has Changed

I want to know, if it's possible, how to check in javascript if an element has changed or an attribute of it?

I mean something like window.onhashchange for an element something like:

document.getElementById("element").onElementChange = function();

As I know onchange is something like this, but will it work if I want to know in this way:

var element = {};
element.attribute = result;

element.attribute.onchange = function();
like image 396
Adam Halasz Avatar asked Nov 27 '10 16:11

Adam Halasz


1 Answers

You might consider a mutation observer.

to do this you first create a callback (fired when the dom element changes)

assign it to an observer var observer = new MutationObserver(callback);

Then tell the observer what to watch observer.observe('<div></div>', observerOptions);

From: Mozilla page on Mutation Observers

like image 91
lucsan Avatar answered Sep 29 '22 19:09

lucsan