jQuery event when element is created

前端 未结 2 753
情话喂你
情话喂你 2021-02-13 20:22

I\'d like to trigger an event when an element is created.

$(document).on(\'load\',\'#TB_title\',function() {
    console.log(\'loaded\');
});

I

2条回答
  •  一生所求
    2021-02-13 20:58

    You can trigger a global custom event:

    $(document).on('load','#TB_title',function() {
      $.event.trigger('nameOfCustomEvent');  
    });
    
    $('#element').bind('nameOfCustomEvent', function(){
      console.log(this);
    });
    

提交回复
热议问题