Jquery 单击-查找已单击元素的索引-它以前出现过多少次?

Jquery 单击-查找已单击元素的索引-它以前出现过多少次?,jquery,Jquery,我需要检查在单击一个=其索引之前有多少productPhoto元素 这不起作用,因为prevAll是针对同级的,我需要搜索productPhoto在某个containernot同级项下出现的次数,而不是在单击该同级项之前出现的次数 那么-在名为products的容器中,单击的productPhoto的索引是什么?好吧,它只需console.log$.productPhoto.index this $(document).on('click', '.productPhoto', function(

我需要检查在单击一个=其索引之前有多少productPhoto元素

这不起作用,因为prevAll是针对同级的,我需要搜索productPhoto在某个containernot同级项下出现的次数,而不是在单击该同级项之前出现的次数

那么-在名为products的容器中,单击的productPhoto的索引是什么?

好吧,它只需console.log$.productPhoto.index this

$(document).on('click', '.productPhoto', function(){
  console.log($(this).prevAll(".productPhoto").length); // * this is photo number 3
});