Detect changes in the DOM

后端 未结 7 2336
温柔的废话
温柔的废话 2020-11-21 05:45

I want to execute a function when some div or input are added to the html. Is this possible?

For example, a text input is added, then the function should be called.<

7条回答
  •  心在旅途
    2020-11-21 06:03

    or you can simply Create your own event, that run everywhere

     $("body").on("domChanged", function () {
                    //dom is changed 
                });
    
    
     $(".button").click(function () {
    
              //do some change
              $("button").append("i am the new change");
    
              //fire event
              $("body").trigger("domChanged");
    
            });
    

    Full example http://jsfiddle.net/hbmaam/Mq7NX/

提交回复
热议问题