1

I'm wondering how to listen to ANY change in the DOM what so ever. For example:

  • A class has been added to something? I want to catch that and process stuff.
  • A new element has been injected? I want to catch that and process stuff.

Literally any DOM edit. I don't need to know what the edit was exactly, just that it has been edited.

Non of the other questions regarding DOM changes in Stackoverflow have a solution for detecting changes in data-attributes or simple element properties for example. Only classes or nodes being inserted / removed.

Any ideas?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Danigoodw
  • 379
  • 3
  • 10
  • https://stackoverflow.com/questions/3219758/detect-changes-in-the-dom – Rastalamm Dec 04 '18 at 23:18
  • 2
    Possible duplicate of [Detect changes in the DOM](https://stackoverflow.com/questions/3219758/detect-changes-in-the-dom) – Dexygen Dec 04 '18 at 23:18
  • Non of the other links have a solution for detecting changes in data-attributes or simple element properties for example. Only classes or nodes being inserted / removed. – Danigoodw Dec 04 '18 at 23:54
  • 2
    There's possibly a third-party application that could provide assistance - have you considered this: https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver – m4rk Dec 05 '18 at 00:12
  • consider using `Proxy`, or you can modify all methods of the `window.document` (maybe you'll need to use `Object.defineProperty`) like wrapping a function outside those methods. Sounds a bit dirty, but it should work. – RZ PAN Dec 05 '18 at 01:31
  • @user3586610 The duplicate question linked to mentions MutationObserver, which is what you probably should be using. If you set `attributes: true`, you'll get those attribute changes. – Brad Dec 05 '18 at 04:49

0 Answers0