jQuery(document).ready(function() { if (localStorage) { // LocalStorage is supported! var firstClass, secondClass, thirdClass; //get the class of the div that's just been clicked jQuery('.col-1-6').click(function() { localStorage.clear(); firstClass = jQuery(this).find('.mini-thumbnail-individual-image:first-child').attr("class"); secondClass = jQuery(this).find('.mini-thumbnail-individual-image:nth-child(2)').attr("class"); thirdClass = jQuery(this).find('.mini-thumbnail-individual-image:last-child').attr("class"); localStorage.setItem("firstDivClass", firstClass); localStorage.setItem("secondDivClass", secondClass); localStorage.setItem("thirdDivClass", thirdClass); }); //convert the string of the last clicked div into a class and then work your magic var currentFirstClass = localStorage.getItem("firstDivClass"); var currentSecondClass = localStorage.getItem("secondDivClass"); var currentThirdClass = localStorage.getItem("thirdDivClass"); // If body class is single i.e. a single project, then update the class with the one from the thumbnails on the homepage if (jQuery('body').hasClass('single')) { console.log("single post"); jQuery('.individual-project:nth-child(3n+1)').addClass(currentFirstClass).removeClass('mini-thumbnail-individual-image'); jQuery('.individual-project:nth-child(2n+2)').addClass(currentSecondClass).removeClass('mini-thumbnail-individual-image'); jQuery('.individual-project:nth-child(3n+3)').addClass(currentThirdClass).removeClass('mini-thumbnail-individual-image'); } else { console.log("nope"); } } else { // No support. Use a fallback such as browser cookies or store on the server. } });