0

I have a div divCoapp1 whose DOM structure can be changed using javascript or ajax calls

How can i attach an eventhandler to its content change?

I have followed this which uses bind method --> Fire jQuery event on div change

Something like this

$('body').on('DOMNodeInserted DOMNodeRemoved','#div1coApp1',function(){
                alert('Hello');
            });

But since bind is now deprecated i want to use on method. How can i do that ?

Community
  • 1
  • 1
Abhishek Singh
  • 10,243
  • 22
  • 74
  • 108

1 Answers1

0

Check this. I am using bind it is working perfectly for me NOTE : change your selector body to document .. Exmaple: link

 $('body').on('DOMNodeRemoved DOMNodeInserted','#rem', function(e) {
   alert("Changed");
});
$('#delete').click(function(){
$('#rem').remove();
});

$('#insert').click(function() {
   $('#rem').append("<p>kamd</p>");
});
kamesh
  • 2,374
  • 3
  • 25
  • 33