jQuery watch for domElement changes?

前端 未结 4 2240
囚心锁ツ
囚心锁ツ 2020-12-02 18:31

I have an ajax callback which injects html markup into a footer div.

What I can\'t figure out is how to create a way to monitor the div for when it\'s contents chang

4条回答
  •  半阙折子戏
    2020-12-02 19:03

    You can listen for changes to DOM elements (your div for example) by binding onto DOMCharacterDataModified tested in chrome but doesn't work in IE see a demo here
    Clicking the button causes a change in the div which is being watched, which in turn fills out another div to show you its working...


    Having a bit more of a look Shiki's answer to jquery listen to changes within a div and act accordingly looks like it should do what you want:

    $('#idOfDiv').bind('contentchanged', function() {
        // do something after the div content has changed
        alert('woo');
    });
    

    In your function that updates the div:

    $('#idOfDiv').trigger('contentchanged');
    

    See this as a working demo here

提交回复
热议问题