Detect paragraph element change with JQuery

后端 未结 7 1947
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-06 17:58

Is it possible to detect if the content of a paragraph has been changed in JQuery ?

I tried the below code.

Text

相关标签:
7条回答
  • 2020-12-06 18:41

    You don't necessarily need JQuery, in modern browsers the web API includes mutation observers. For older browsers there are mutation events.

    mutation observer example:

    var observer = new MutationObserver(function(mutations) {
      mutations.forEach(function(mutation) {
        alert(mutation.type);
      });    
    });
    

    Fiddle with mutation observers: http://jsfiddle.net/nnbqye55/5/

    For JQuery/older IE support, see: https://github.com/kapetan/jquery-observe

    0 讨论(0)
提交回复
热议问题