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

后端 未结 13 2294
旧巷少年郎
旧巷少年郎 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 07:16

    Using Javascript MutationObserver

      //More Details https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver
     // select the target node
    var target = document.querySelector('mydiv')
    // create an observer instance
    var observer = new MutationObserver(function(mutations) {
      console.log($('mydiv').text());   
    });
    // configuration of the observer:
    var config = { attributes: true, childList: true, characterData: true };
    // pass in the target node, as well as the observer options
    observer.observe(target, config);
    
    0 讨论(0)
提交回复
热议问题