How to detect content change event on a div

前端 未结 3 1341
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-15 07:52

I am trying to make an editor everything working fine till now, but now I need to make a handler which could detect any change made in a div or any content edited in the div

3条回答
  •  旧巷少年郎
    2020-12-15 08:46

    You can bind a custom event to the div and trigger that event upon change

    Demo in Stack Snippets and jsFiddle:

    $(function() {
    
      $('#wrapper').bind("contentchange", function() {
        console.log("Captured content change event"); 
      });
    
      $("#btn").click(function() {
        $('#wrapper').html("new value").trigger("contentchange");
      });
      
    });
    
    
    

提交回复
热议问题