jQuery- Detect change in the content of a SPAN field

后端 未结 2 2188
没有蜡笔的小新
没有蜡笔的小新 2021-02-07 18:48

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




        
2条回答
  •  广开言路
    2021-02-07 19:06

    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

提交回复
热议问题