javascript - jquery Trigger delegate event for nth element onload -
in page have 10 images have same class "select-option"
my html is
<div class="select-option swatch-wrapper selected" data-name="a scary monster" data-value="a-very-scary-monster"> <a href="#" style="width:120px;height:120px;" title="" class="swatch-anchor"> <img src="image ur1" alt="" class="" width="120" height="120"></a></div>
similarly have 10 images.
function init_swatches() { $('.select-option').delegate('a', 'click', function(event) { ///////////// code here var $the_option = $(this).closest('div.select-option'); }); }
i want preselect 3rd image. thew selected image has class 'selected', others not. how trigger 3rd or 4th element on load. how manually trigger delegate event nth element.
here want trigger click event
first bind click event on anchor tag
$('.select-option').delegate('a', 'click', function(event) { ///////////// code here var $the_option = $(this).closest('div.select-option'); });
then manuaaly trigger click event of 3rd element given below
$('.select-option a').eq(2).click()
or
$('.select-option a').eq(2).trigger("click")
Comments
Post a Comment