<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<link rel="stylesheet" href="https://jsfiddle.net/ewebster/a81v1q46/35/href=%22https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css">
<form>
<input type="text" id="searchEntry" placeholder="Search">
<input type="submit" id="searchBtn" class="searchButton"/>
</form>
<p id="result"></p>
<p id="test"></p>
<ul>
<li> <button class="filter-button" data-filter="all">All </button></li>
<li><button class="filter-button" data-filter="short">Short </button></li>
<li> <button class="filter-button" data-filter="tall">Tall </button></li>
<li><button class="filter-button" data-filter="big">Big </button></li>
<li> <button class="filter-button" data-filter="small">Small </button></li>
<li> <button class="filter-button" data-filter="many">Many</button> </li>
<li><button class="filter-button" data-filter="few">Few </button></li>
</ul>
<div class="filter item all big tall">
Big and Tall
</div>
<div class="filter item all short small">
Short and Small
</div>
<div class="filter item all big short">
Big and Short
</div>
<div class="filter item all tall small">
Tall and Small
</div>
<div class="filter item all big few">
Big and Few
</div>
<div class="filter item all many small">
Many and Small
</div>
<div class="filter item all few small">
Few and Small
</div>
<div class="filter item all short few small">
Short and Small and Few
</div>
<div class="filter item all big tall many">
Big and Tall and Many
</div>
$(document).ready(function () {
//declare a global variable
var filterVal;
//check if sessionStorage exists and if so, if there is a var called fillTerm
//if not, set it to a default value (all)
if (sessionStorage && sessionStorage.getItem("filTerm")) {
filterVal = sessionStorage.getItem("filTerm");
} else {
filterVal = "all";
sessionStorage.setItem("filTerm", filterVal);
}
//now let's attach some interaction to our buttons
$(".filter-button").on("click", function () {
//get the value for our filter
filterVal = $(this).attr("data-filter");
//store it in the session storage
sessionStorage.setItem("filTerm", filterVal);
console.log(sessionStorage);
console.log(filterVal);
//call our view update function
updateView();
});
//this is the function that manipulates the UI
function updateView() {
//default situation: all is visible
if (!filterVal || filterVal === "all") {
$('.filter').show();
}
//hide all and show filtered values
else {
$(".filter").hide();
$('.filter').filter('.' + filterVal).show();
console.log("searchTerm");
console.log("filterVal");
}
};
//update the view when the page loads
updateView();
$(".searchButton").click(function () {
var term = $(this).attr('data-filter');
var searchTerm = document.getElementById("searchEntry").value;
console.log("searchTerm");
console.log("filterTerm");
})
});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.