get position of .length jquery -


i using $('.gallery img').click call function , using .length value in comparison, need position of img in div. .gallery div array , img in number "0 9" click third img , 2 or fifth 1 , 4.

you can use jquery index method getting index of clicked image element in jquery collection:

var $img = $('.gallery img').on('click', function() {     var = $img.index(this); }); 

if image wrapper has image children can can use index method without passing element:

var = $(this).index(); 

Comments

Popular posts from this blog

hibernate - How to load global settings frequently used in application in Java -

python 3.x - Mapping specific letters onto a list of words -

objective c - Ownership modifiers with manual reference counting -