My question is somewhat weird, but can i add events for any DOM elements(div), like 'onHtmlChange', to be notified when that div has changed their content?
Asked
Active
Viewed 7,289 times
10
-
Ideally, you shouldn't ever require such an event. What exactly would make the HTML of any given element change? – James Aug 24 '09 at 22:02
-
GMaps is feeding an DIV with his content. But the root of my question is just to mimics a dataflow programming approach :P – Frangossauro Aug 24 '09 at 23:33
2 Answers
8
Check out DOMNodeInserted and DOMNodeRemoved.
Ben Nadel recently blogged the following: Detecting When DOM Elements Have Been Removed With jQuery

Sampson
- 265,109
- 74
- 539
- 565
-
Seems like the OP wants to know when HTML content inside of the divs has changed though. – seth Aug 24 '09 at 20:58
-
@seth —Browsers which use the W3C model should fire both `DOMNodeInserted` and `DOMNodeRemoved` when changing a node's contents, even it it's just text nodes (just tested FF3). The IE trick mentioned in the linked article could easily be extended to `.html()` and `.text()` to mimic this. – Ben Blank Aug 24 '09 at 21:12
1
The DOMNodeInserted and DOMNodeRemoved are part of the Mutation Events which is now deprecated. Hence, you need to take a look on Mutation Observer. I did the same in one of my project which is I needed to listen to the DOM changes of a certain element., e.g. DOM append, remove, attribute, and data changes.
These links will help you :

Community
- 1
- 1

Ratih Nurmalasari
- 588
- 6
- 15