jQuery - Programmatically Trigger Event

后端 未结 2 881
谎友^
谎友^ 2021-01-21 04:19

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

var $thumbs = $(\'#PhotoGalleryThumbs .tile\');
var          


        
相关标签:
2条回答
  • 2021-01-21 05:05

    Similar to the previous suggestion of

    $($thumbs[7]).click();
    

    you can use

    $thumbs.eq(7).click();
    

    For clarification, array indexing into a jQuery collection gives you the DOM Element at that position, whereas .eq(n) gives you a new jQuery object which references only the indexed element.

    http://api.jquery.com/eq/

    0 讨论(0)
  • 2021-01-21 05:16
    $thumbs.click();
    

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

    0 讨论(0)
提交回复
热议问题