Listen to changes within a DIV and act accordingly

后端 未结 7 607
谎友^
谎友^ 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:19

    You can opt to create your own custom events so you'll still have a clear separation of logic.

    Bind to a custom event:

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

    In your function that updates the div:

    // all logic for grabbing xml and updating the div here ..
    // and then send a message/event that we have updated the div
    $('#laneconfigdisplay').trigger('contentchanged'); // this will call the function above
    

提交回复
热议问题