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');
});
精彩评论