开发者

trigger click on element loaded by ajax

how can i trigger click method of an element loaded by ajax runs on click event of a parent element?

i 开发者_StackOverflow中文版want it happen of page load time.


To trigger an event handler using jQuery:

  • .trigger()
  • .triggerHandler()

Could look like:

$(document).ready(function() {
    $('#mybutton').trigger('click');
});

** edit **

After reading your comment, you can use jQuery's .live() or better .delegate() method to have a "live binding" on current and new elements.

$(document).ready(function() {
    $('#mybutton').live('click', function() {
       // do something
    });
});

Ref.: .live(), .delegate()


Try to use .live() method. for more details look at this link.


I had faced same problem in my experience.

My solution is this.

jQuery(document).ready(function($){
$("#element_id").bind('click',function(){
alert('click event is triggered');
});

$("#element_id").trigger('click');
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜