$(document).on('click', '.productPhoto', function(){
console.log($(this).prevAll(".productPhoto").length); // * this is photo number 3
});
我需要检查单击的ProductPhoto
元素之前有多少个(=其索引)
这是不起作用的,因为Prevall
是针对同级的,并且我需要搜索在单击容器之前ProductPhoto
在某个容器(而不是同级)下出现的次数。
那么--在名为products
的容器中,单击的productphoto
的索引是什么?
好吧,它就像console.log($(“。productphoto”)。index(this));
一样简单