Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I monitor the DOM for changes?

Is there a way - using jQuery or otherwise - to monitor the DOM for insertions, deletions, updates to styles, etc?

like image 527
Josh Rickard Avatar asked Mar 16 '09 01:03

Josh Rickard


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.

What are mutation observers?

MutationObserver is a built-in object that observes a DOM element and fires a callback when it detects a change. We'll first take a look at the syntax, and then explore a real-world use case, to see where such thing may be useful.


1 Answers

See "MutationEvent" elements in here: https://developer.mozilla.org/en/DOM/DOM_event_reference but those are deprecated.

jQuery now features a way to attach events to existing AND future elements corresponding to a selector: http://docs.jquery.com/Events/live#typefn

It may be a trick you could use for lack of proper DOM Node modification info.

like image 194
Julian Aubourg Avatar answered Oct 06 '22 20:10

Julian Aubourg