Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery - Programmatically Trigger Event

I need to programmatically trigger a click event that's being handled by jQuery. Here's the current code:

var $thumbs = $('#PhotoGalleryThumbs .tile');
var $zoom = $('#PhotoGallery #PhotoGalleryZoom img');
var $description = $('#PhotoGallery #PhotoGalleryDescription');

$thumbs.click(function(event) {
    event.preventDefault();
    var $thumb = $(this);
    $thumb.addClass('selected')
        .siblings().removeClass('selected');
    $zoom.attr('src', $thumb.children('a').attr('href'));
    $description.html($thumb.find('img').attr('alt'));
});

I am having a mental block working out how to create a function out of the event handling code and then arbitrarily calling it for an element in the $thumbs object.

like image 923
Sonny Avatar asked Sep 29 '26 18:09

Sonny


1 Answers

$thumbs.click();

This would trigger the click event. Is this what you're looking for?

like image 72
Evgeny Shadchnev Avatar answered Oct 02 '26 05:10

Evgeny Shadchnev