JQuery element index in array

arraysjquery

I have several images loaded into the DOM via jQuery. Each image has 'display: none' aside from one which is 'display: block'. It's this image which I need to find the index of once selecting the img array from the DOM.

The trouble is, img[style="display: block"] doesn't seem to be working as 'display' isn't the only style set on the element. There's top, left, etc…

How can I find the index of the image with display:block from a selection of images with display:none?

Current code I'm using:

slideshowStart = jQuery('.gallery .slideshow img[style="display: block"]').index(this);

Best Answer

You can use the :visible selector for this:

var slideshowStart = $(".gallery .slideshow img:visible").index(this);