0

I'm curious to know if there is an efficient way of detecting ANY change of the DOM.

Read that DOMSubtreeModified is not compatible with modern browsers.

I was thinking in hashing all the information contained in the DOM, and compare it with a timer, with the refreshed DOM.

I'm just trying to fire an event when the DOM is changed.

What do you think of this hashing the DOM approach?

jacktrades
  • 7,224
  • 13
  • 56
  • 83
  • possible duplicate of [is it possible to tell if DOM was modified, and which part?](http://stackoverflow.com/questions/2510057/is-it-possible-to-tell-if-dom-was-modified-and-which-part) – Naftali Aug 02 '12 at 21:16
  • 1
    Ever heard about [Mutation observers](https://developer.mozilla.org/en/DOM/DOM_Mutation_Observers)? These do not capture *all* changes though: When I execute set an attribute, and immediately revert it, it's not reported. – Rob W Aug 02 '12 at 21:18
  • Just curious, on how to trigger an action on any DOM change. – jacktrades Aug 02 '12 at 21:20
  • Chances are there is a better way of accomplishing what you need to accomplish. Perhaps an object that you use to make your modifications to the DOM, which can also have whatever functionality you are trying to achieve built in. – dqhendricks Aug 02 '12 at 21:28
  • @jacktrades: What's wrong with `DOMSubtreeModified`? – Bergi Aug 02 '12 at 21:28
  • @Bergi: AFAIK just the browser issue – jacktrades Aug 02 '12 at 21:30
  • Which issue? Could you link the page where you have read that it "*is not compatible with modern browsers*"? – Bergi Aug 02 '12 at 21:34
  • [here](http://stackoverflow.com/a/3634070/1341526) – jacktrades Aug 02 '12 at 21:36
  • 1
    `DOMSubtreeModified` has never made into Opera but otherwise is available in current versions of WebKit, Mozilla and IE. However, DOM mutation events are deprecated in DOM4 and are to be replaced by DOM mutation observers, and it will be a while before those are available in a majority of users' browsers. – Tim Down Aug 02 '12 at 23:33

2 Answers2

2

This similar question should help: Is there a JavaScript/jQuery DOM change listener?

And this will also set you in the right direction: http://www.w3.org/TR/DOM-Level-2-Events/events.html#Events-eventgroupings-mutationevents

Also this may help from MDN: https://developer.mozilla.org/en/DOM_Events

Community
  • 1
  • 1
Lemex
  • 3,772
  • 14
  • 53
  • 87
0

The Mutation Event is currently deprecated because of it's performance issue. Hence, Please use the Mutation Observer. I did the DOM changes/modification listener in one of my project using Mutation Observer and it worked great! For your further implementation, these links will help you:

  1. http://gabrieleromanato.name/jquery-detecting-new-elements-with-the-mutationobserver-object/
  2. Is there a JavaScript/jQuery DOM change listener?
  3. https://github.com/kapetan/jquery-observe
Community
  • 1
  • 1