I think I need to use jQuery’s index() function but I’m doing it all wrong! I have a bunch of table cells with images inside, and one of them will have a class called “current”. How can I tell which image has the class? I need an integer to work with.
I’m thinking something like this but I get “-1”, nothing found..
var prev = $('#full_width_gallery').index('img');
Any ideas where I’m going wrong?
Select the images:
var $images = $('#full_width_gallery img');Retrieve the index of the image with class “.current”:
$images.filter('.current').index();– this will be the index of that image in $images, not some kind of “global” index!In total:
or: