The problem: I have a jQuery var setup like so:
var count = $("#gallery li:visible").length;
alert(count);
This finds all the gallery li's that are currently visible on the page. The number changes when the pagination is triggered, as people can select categories.
I want to be able to use this count
to then look at the 3rd item of every count
and addClass
of end_item
(as i have 3 in a row)
My HTML:
<ul id="gallery">
<li class="gallery_image" data-id="" data-type="">
<img src=""/><div class="thumb_bg"></div>
<img src="" data-original="" />
</li>
<li class="gallery_image" data-id="" data-type="">
<img src=""/><div class="thumb_bg"></div>
<img src="" data-original="" />
</li>
<li class="gallery_image" data-id="" data-type="">
<img src=""/><div class="thumb_bg"></div>
<img src="" data-original="" />
</li>
<li class="gallery_image" data-id="" data-type="">
<img src=""/><div class="thumb_bg"></div>
<img src="" data-original="" />
</li>
</ul>
Currently trying:
$('#gallery li').each( function(count) {
if( count % 3 != 2 )
return
$(this).addClass('end')
})
I am not going to have exactly 3 on the page, it could be anything from 2 - 12, so i need to find EVERY 3rd item currently visible
EDIT: My code seems to work... however only when the page first loads. If i use a filter item on my gallery, the code is counting the hidden items, even though i am re-calling the jQuery once a filter is clicked.