/ Published in: jQuery

Quick little clientside script to pick out every 3rd image and add a class of last to it.
I needed this because the images were layed out in 3 columns, adding a margin to the right hand side would leave a large gap on the right hand side which i didn't want. This now allows me to remove the margin for the last image.
I needed this because the images were layed out in 3 columns, adding a margin to the right hand side would leave a large gap on the right hand side which i didn't want. This now allows me to remove the margin for the last image.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
//Save the context in a var var $main = $("#mainContent"); //If the container exists if($(".ngg-albumoverview").length){ //Loop through each image, including the index of the object(i) $(".ngg-album", $main).each(function(i){ //Since 0 based add one, for every 3rd object remainder will equal 0 var remainder = (i + 1) % 3; //Add a class of last when the remainder is 0 if(remainder === 0){ $(this).addClass("last"); } }); }
Comments
