I need to get an index of the item I clicked, but only an index of items with a specific class.
<div class="gallery">
<div class="gallery-item"></div>
<div class="gallery-item"></div>
<div class="gallery-item select-gallery-item"></div> <!-- click on this -->
<div class="gallery-item"></div>
<div class="gallery-item"></div>
<div class="gallery-item select-gallery-item"></div>
<div class="gallery-item select-gallery-item"></div>
<div class="gallery-item select-gallery-item"></div>
</div>
$('.gallery').on('click', '.select-gallery-item', function () {
$(this).index();
};
For example, I click on this element with a class '.select-gallery-item', I will get an index - 2. But among the elements with the class '.select-gallery-item', its index - 0