jQuery Event : Detect changes to the html/text of a div

后端 未结 13 2285
旧巷少年郎
旧巷少年郎 2020-11-22 06:15

I have a div which has its content changing all the time , be it ajax requests, jquery functions, blur etc etc.

Is there a way

13条回答
  •  孤街浪徒
    2020-11-22 06:55

    If you don't want use timer and check innerHTML you can try this event

    $('mydiv').bind('DOMSubtreeModified', function(){
      console.log('changed');
    });
    

    More details and browser support datas are Here.

    Attention: in newer jQuery versions bind() is deprecated, so you should use on() instead:

    $('body').on('DOMSubtreeModified', 'mydiv', function(){
      console.log('changed');
    });
    

提交回复
热议问题