I've found a very useful Jquery example to filter divs based on changing select options.
Here is the fiddle: https://jsfiddle.net/vgdwyqxb/
My problem is: I use this code for filtering projects and every single project has a URL that goes to another page. When a user clicks on a project, he/she goes to project detail page. On those pages, there is a "Go Back" button. When they go back, all filtering selections are lost. I want to hold the filter selections.
I added a goBack() method in other page to go back to filter page. When I click on goback, filter page remembers which option was selected but all divs appear (not filtering divs). As far as i know "changing option" must be done in order to filter divs, so when i go back to filter page, even my last selected option is selected, it doesn't filter anymore.
My question is: What should i do to make filter page remember when users go back from project detail page?
Thanks in advance.
jQuery('#selectContainer select').on('change', function() {
var color = jQuery('#select-1').val();
var shape = jQuery('#select-2').val();
var style = jQuery('#select-3').val();
jQuery('div.object').hide();
jQuery('div.object').each(function() {
if(jQuery(this).hasClass(color) && jQuery(this).hasClass(shape) && jQuery(this).hasClass(style)) {
jQuery(this).show();
}
});
});
//$( document ).ready(function() {
$('#btnAuckland').click(function(){
$('#select-1').val('Red').trigger('change');
})
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.2/jquery.min.js"></script>
<div id="selectContainer">
<select name="select-1" id="select-1">
<option value="allColors">All</option>
<option value="Red">Red</option>
<option value="Blue">Blue</option>
</select>
<select name="select-2" id="select-2">
<option value="allShapes">All</option>
<option value="Square">Square</option>
<option value="Circle">Circle</option>
</select>
<select name="select-3" id="select-3">
<option value="allStyles" selected>All</option>
<option value="Solid">Solid</option>
<option value="Outline">Outline</option>
</select>
</div>
<hr />
<div class="object allColors allShapes allStyles Red Square Solid">
<p><a href="nextpage.html"> This is a solid, red square. </a> </p>
</div>
<div class="object allColors allShapes allStyles Red Square Outline">
<p>This is a red, square outline.</p>
</div>
<div class="object allColors allShapes allStyles Red Circle Solid">
<p>This is a solid, red circle.</p>
</div>
<div class="object allColors allShapes allStyles Red Circle Outline">
<p>This is a red, circle outline.</p>
</div>
<div class="object allColors allShapes allStyles Blue Square Solid">
<p>This is a solid, blue square.</p>
</div>
<div class="object allColors allShapes allStyles Blue Square Outline">
<p>This is a blue, square outline.</p>
</div>
<div class="object allColors allShapes allStyles Blue Circle Solid">
<p>This is a solid, blue circle.</p>
</div>
<div class="object allColors allShapes allStyles Blue Circle Outline">
<p>This is a blue, circle outline.</p>
</div>