Detect element content changes with jQuery

后端 未结 15 2530
余生分开走
余生分开走 2020-11-22 04:19

change() function works and detects changes on form elements, but is there a way of detecting when a DOM element\'s content was changed?

This does not w

15条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-22 05:18

    We can achieve this by using Mutation Events. According to www.w3.org, The mutation event module is designed to allow notification of any changes to the structure of a document, including attr and text modifications. For more detail MUTATION EVENTS

    For Example :

    $("body").on('DOMSubtreeModified', "#content", function() {
        alert('Content Modified'); // do something
    });
    

提交回复
热议问题