Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any "on DOM change" event? [duplicate]

Possible Duplicate:
Detect changes in the DOM

I need to setup an event handler, which should fire whenever something is appended/changed/removed on the DOM. This answer does not work in my case. The DOM can be modified by third party developers, and on each DOM change, we need to run our script to validate the code. The event should not fire on input/textarea/select change.

We do not target all browsers. As long as it works on Webkit (Chrome, Safari), it's good enough.

Any ideas?

like image 924
Sherzod Avatar asked Feb 27 '12 19:02

Sherzod


People also ask

What happens when the DOM changes?

When you update the DOM, the reflow and repaint happen. Every time the DOM changes, the browser needs to recalculate the CSS, do a layout and repaint the web page. React doesn't really do anything new. It's just a strategic move.

How do you detect change in DOM?

We insert a new p element after 1 second 5 times. We pass in a callback into the MutationObserver constructor that runs when the DOM changes. Then we call observe on the element that we want to observe changes for. subtree set to true means that we watch for child element changes.

How does angular determine DOM changes?

Angular does not provide something built-in for that purpose. You can use MutationObserver to detect DOM changes.

Are events part of DOM?

Events are a part of the Document Object Model (DOM) Level 3 and every HTML element contains a set of events, which can trigger JavaScript code.


1 Answers

DOM mutation events (I believe not supported in all browsers) .. see http://en.wikipedia.org/wiki/DOM_events#Common.2FW3C_events

like image 75
Jim Blackler Avatar answered Sep 16 '22 17:09

Jim Blackler