Note that there are some explanatory texts on larger screens.

plurals
  1. POWatching for DOM changes, the elegant way
    primarykey
    data
    text
    <p>I need to watch for an attribute change on any of the children of a specific DOM element. So far, I have been using <a href="https://developer.mozilla.org/en/DOM/Mutation_events" rel="noreferrer">mutation events</a>.</p> <p>The problem was - they were buggy: e.g. under Chromium, <code>DOMAttrModified</code> was not fired but <code>DOMSubtreeModified</code> was. The problem was easy to solve: because according to the specification, <code>DOMSubtreeModified</code> is fired if any of the other events is fired, so I just listened to <code>DOMSubtreeModified</code>.</p> <p>Anyway, Chromium, in the recent versions, stopped firing anything if an attribute has been modified. </p> <p>The new <a href="http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers" rel="noreferrer">Mutation Observer API</a>, however, works flawlessly.</p> <p>Until now, I only need to fire a callback upon ANY change of the subtree of a specific element - simply because nothing else is supposed to change - so I solved my problem by just using mutation events &amp; mutation observer (when available) in the same piece of code.</p> <p>However, now I need to do more powerful filtering of the events (e.g. on new node, on removed node) - so is there <strong>a library, possibly a jQuery plug-in</strong>, that would allow me to elegantly use <strong>both</strong> of these APIs - <code>MutationObserver</code> if available and mutation events as a fallback, with the ability to filter for specific event types (e.g. element added, attribute changed).</p> <p>E.g. </p> <pre><code>$("#test").watch({onNewElement: 1}, function(newElement){}) $("#test").watch({onNewAttribute: 1}, function(modifiedElement) {}) </code></pre> <p>Or without jQuery</p> <pre><code>watchChanges("#test", {onNewElement: 1}, function(newElement){}) watchChanges("#test", {onNewAttribute: 1}, function(modifiedElement){}) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload