I have an interesting situation. I need to trigger a live click, because simple click doesn't work.
This is what I have:
$('.text').trigger('click');
but I need something like this:
$('.text').trigger(live('click' ...));
or something to fix this problem.
This is my code:
$(".Sets a.largeImage").fancybox({
'onComplete': function(){
return errorimage(myurl);
}
});
function errorimage(url) {
$("#fancybox-img").live('click', function(){
$('.lightbox:first').trigger('click');
});
$('#fancybox-img').trigger('click');
}
The idea is that I want to trigger $('.lightbox:first').trigger('click');
, but in live mode, because simple click doesn't work!
Thank you !!!!
jQuery live() MethodThe live() method attaches one or more event handlers for selected elements, and specifies a function to run when the events occur. Event handlers attached using the live() method will work for both current and FUTURE elements matching the selector (like a new element created by a script).
jQuery trigger() Method The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.
$('#b1'). on('click', function(){ $('#select_item'). trigger('change'); }); $('#select_item'). on('change', function(){ var jbyr = $(this).
jQuery error() Method The error() method triggers the error event, or attaches a function to run when an error event occurs.
The best solution would be to put your click handler in a separate function.
You can then call this function both from the live click handler and when you want to manually trigger the click.
I had the same problem when using Lightbox2 which binds the click event using live(). In my case the solution was to trigger the event like this:
jQuery**('a[rel^="lightbox"]')**.ready(function () {
jQuery("#myimglink").trigger("click");
})
As you can see i was triggering the event only after all the images that are using lightbox are ready. Hope it will help you all - this being my first contribution to stackoverflow :).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With