jQuery- Detect change in the content of a SPAN field

后端 未结 2 1989
我寻月下人不归
我寻月下人不归 2021-02-07 18:18

I have the below piece of code which is used to simulate a text box:




        
2条回答
  •  生来不讨喜
    2021-02-07 19:23

    You can use this event DOMSubtreeModified:

    $("span").on('DOMSubtreeModified', function () {
      alert("Span HTML is now " + $(this).html());
    });
    

    Snippet

    $(function () {
      $("a").click(function () {
        $("span").html("Hello, World!");
      });
      $("body").on('DOMSubtreeModified', "span", function () {
        alert("Span HTML is now " + $(this).html());
      });
    });
    
    Hello
    Click

提交回复
热议问题