how to trigger Live() click in jquery

AlexC picture AlexC · Jun 30, 2010 · Viewed 14.1k times · Source

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 !!!!

Answer

SLaks picture SLaks · Jun 30, 2010

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.