Reputation: 565
$(document).on('click', '.productPhoto', function(){
console.log($(this).prevAll(".productPhoto").length); // * this is photo number 3
});
I need to check how many productPhoto
elements there are before the clicked one (= its index)
This is not working because prevAll
is for siblings, and i need to search how many times productPhoto
appears under some container(not sibling) before the clicked one.
So - in the container named products
, what is the index of productPhoto
that clicked ?
Upvotes: 0
Views: 23
Reputation: 565
Well, its as simple as console.log( $( ".productPhoto" ).index( this ) );
Upvotes: 1