1

In jQuery how can I watch a div to determine if it has changed so that I can rebind events and perform some other action as needed?

user974896
  • 1,795
  • 4
  • 28
  • 48

2 Answers2

1

If the div has dynamic content I would like to tell you about event delegation.

Event delegation allows you to avoid adding event listeners to specific nodes; instead, the event listener is added to one parent.1

To use event delegation in jQuery you use the on method and provide a selector argument.

Jonas G. Drange
  • 8,749
  • 2
  • 27
  • 38
0

You could use DOMSubtreeModified event(see here)

$('my-selector').bind('DOMSubtreeModified', function() {
  console.log('Children have been modified');
});

I haven't checked the supported nature of this event but in chrome it works.

Unfortunately : Why is the DOMSubtreeModified event deprecated in DOM level 3?

Community
  • 1
  • 1
Liviu T.
  • 23,584
  • 10
  • 62
  • 58