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

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -