2

How can I detect when the document changes?

I know I could do something like this:

var lastHTML = document.body.innerHTML;
setInterval(function() { if(document.body.innerHTML != lastHTML) { DOMupdated() } }, 500);

But is there an event handler I can put in place, like onchange?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
PitaJ
  • 12,969
  • 6
  • 36
  • 55

1 Answers1

6

There's the old DOM Mutation Events, and there's the new DOM Mutation Observers.


For a quick overview of them both (and why the newer [more complex] API is better), check out this post:

Detect DOM Changes with Mutation Observers.


P.S. Don't miss the comments there...

Joseph Silber
  • 214,931
  • 59
  • 362
  • 292