Listen to changes within a DIV and act accordingly

后端 未结 7 608
谎友^
谎友^ 2020-11-28 23:34

I have a function that grabs an XML document and transforms it according to an XSL document. It then places the result into a div with the id laneconfigdisplay

7条回答
  •  青春惊慌失措
    2020-11-29 00:24

    There is an excellent jquery plugin, LiveQuery, that does just this.

    Live Query utilizes the power of jQuery selectors by binding events or firing callbacks for matched elements auto-magically, even after the page has been loaded and the DOM updated.

    For example you could use the following code to bind a click event to all A tags, even any A tags you might add via AJAX.

    $('a').livequery('click', function(event) { 
        alert('clicked'); 
        return false; 
    }); 
    

    Once you add new A tags to your document, Live Query will bind the click event and there is nothing else that needs to be called or done.

    Here is a working example of its magic...

提交回复
热议问题