build filter js
JavaScript
filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
// Add the "show" class (display:block) to the filtered elements, and remove
the "show" class from the elements that are not selected
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i],
"show");
if (x[i].className.indexOf(c) > -1)
w3AddClass(x[i], "show");
}
}
// Show filtered
elements
function w3AddClass(element,
name) {
var i, arr1, arr2;
arr1 = element.className.split("
");
arr2 = name.split(" ");
for (i = 0; i < arr2.length;
i++) {
if (arr1.indexOf(arr2[i]) == -1) {
element.className += " " + arr2[i];
}
}
}
// Hide elements that are not selected
function w3RemoveClass(element, name) {
var i, arr1, arr2;
arr1 = element.className.split(" ");
arr2 = name.split(" ");
for (i = 0; i < arr2.length; i++) {
while
(arr1.indexOf(arr2[i]) > -1) {
arr1.splice(arr1.indexOf(arr2[i]), 1);
}
}
element.className = arr1.join(" ");
}
// Add active class
to the current control button (highlight it)
var btnContainer = document.getElementById("myBtnContainer");
var btns =
btnContainer.getElementsByClassName("btn");
for (var i = 0; i < btns.length; i++)
{
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("active");
current[0].className = current[0].className.replace(" active", "");
this.className += " active";
});
}
<!-- Control buttons -->
<div id="myBtnContainer">
<button
class="btn active" onclick="filterSelection('all')"> Show all</button>
<button class="btn" onclick="filterSelection('cars')"> Cars</button>
<button class="btn" onclick="filterSelection('animals')"> Animals</button>
<button class="btn" onclick="filterSelection('fruits')"> Fruits</button>
<button class="btn" onclick="filterSelection('colors')"> Colors</button>
</div>
<!-- The filterable elements. Note that
some have multiple class names (this can be used if they belong to multiple
categories) -->
<div
class="container">
<div
class="filterDiv cars">BMW</div>
<div class="filterDiv colors
fruits">Orange</div>
<div class="filterDiv cars">Volvo</div>
<div class="filterDiv colors">Red</div>
<div class="filterDiv cars
animals">Mustang</div>
<div class="filterDiv colors">Blue</div>
<div class="filterDiv animals">Cat</div>
<div class="filterDiv
animals">Dog</div>
<div class="filterDiv fruits">Melon</div>
<div class="filterDiv fruits animals">Kiwi</div>
<div class="filterDiv
fruits">Banana</div>
<div class="filterDiv fruits">Lemon</div>
<div class="filterDiv animals">Cow</div>
</div>
Also in JavaScript:
- Title
- add "hr" from javascript
- Category
- JavaScript
- Title
- how to add object to array javascript
- Category
- JavaScript
- Title
- close exit app react native
- Category
- JavaScript
- Title
- how to get data in json format in javascript
- Category
- JavaScript
- Title
- getelementbyid
- Category
- JavaScript
- Title
- can we import jquery library from developer tools
- Category
- JavaScript
- Title
- array spread operator in javascript
- Category
- JavaScript
- Title
- convert json to object jackson
- Category
- JavaScript
- Title
- detect browser javascript
- Category
- JavaScript
- Title
- electron scrollbar
- Category
- JavaScript
- Title
- events js 292 throw er Unhandled 'error' event ^ Error getaddrinfo ENOTFOUND x86_64-apple-darwin13.4.0 at GetAddrInfoReqWrap.onlookup [as oncomplete]
- Category
- JavaScript
- Title
- compare the triplets hackerrank solution in javascript
- Category
- JavaScript
- Title
- daterangepicker set maxdate
- Category
- JavaScript
- Title
- how to compare two strings in javascript if condition
- Category
- JavaScript
- Title
- If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.
- Category
- JavaScript
- Title
- how to add button react native app.js
- Category
- JavaScript
- Title
- array sort by key javascript
- Category
- JavaScript
- Title
- discord.js multiple embeds
- Category
- JavaScript
- Title
- how to get the height of window in javascript
- Category
- JavaScript
- Title
- How to uninstall npm modules in node js?
- Category
- JavaScript
- Title
- How to check if a member has a role discord.js
- Category
- JavaScript
- Title
- angular moment pipe timeAgo
- Category
- JavaScript
- Title
- express redirect
- Category
- JavaScript
- Title
- how to remove a property from an object in javascript
- Category
- JavaScript
- Title
- convert boolean to string javascript
- Category
- JavaScript
- Title
- async reduce javascript
- Category
- JavaScript
- Title
- crypto.com api
- Category
- JavaScript
- Title
- Given a list of daily temperatures T, return a list such that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this is possible, put 0 instead javascript
- Category
- JavaScript
- Title
- input output ionic
- Category
- JavaScript
- Title
- how to create 3d gallery using javascript
- Category
- JavaScript
- Title
- iterate over array javascript
- Category
- JavaScript
- Title
- how to convert json to bootstrap treeview format
- Category
- JavaScript
- Title
- import jquery
- Category
- JavaScript
- Title
- auto refresh page javascript
- Category
- JavaScript
- Title
- embed jquery
- Category
- JavaScript
- Title
- get parent element using jquery
- Category
- JavaScript
- Title
- how pass data from body in koa js
- Category
- JavaScript
- Title
- for in loops javascript
- Category
- JavaScript
- Title
- change bloodhound remote dynamically
- Category
- JavaScript
- Title
- git remote url change
- Category
- JavaScript
- Title
- javascript Clone an array
- Category
- JavaScript
- Title
- how to link javascript to html
- Category
- JavaScript
- Title
- encode url javascript
- Category
- JavaScript
- Title
- angular right click on link
- Category
- JavaScript
- Title
- check if value is a string javascript
- Category
- JavaScript
- Title
- case in javascript
- Category
- JavaScript
- Title
- convert object to json javascript
- Category
- JavaScript
- Title
- how to make all lowercase in js
- Category
- JavaScript
- Title
- how to get nth fibonacci javascript
- Category
- JavaScript
- Title
- import react
- Category
- JavaScript
- Title
- if statemnt shorthand js without else
- Category
- JavaScript
- Title
- get current directory vbscript
- Category
- JavaScript
- Title
- bootstrap datepicker js cdn
- Category
- JavaScript
- Title
- Attempted import error: 'uuid' does not contain a default export (imported as 'uuid').
- Category
- JavaScript
- Title
- javascript button onclick programmatically
- Category
- JavaScript
- Title
- how to get the index of an array in javascript
- Category
- JavaScript
- Title
- check first two number jquery
- Category
- JavaScript
- Title
- disable mixed content via javascript
- Category
- JavaScript
- Title
- AJAX JAVASCRIPT TUTORIALS
- Category
- JavaScript
- Title
- initialize array javascript
- Category
- JavaScript
- Title
- angular.min.js version
- Category
- JavaScript
- Title
- how to make a text editor in html
- Category
- JavaScript
- Title
- alphabet array js
- Category
- JavaScript
- Title
- how to add elements in javascript html
- Category
- JavaScript
- Title
- dynamic forms in react
- Category
- JavaScript
- Title
- hello
- Category
- JavaScript
- Title
- does a function inside a function need to be called?
- Category
- JavaScript
- Title
- autocomplete list angular 8 material
- Category
- JavaScript
- Title
- hide urls in .env in react app
- Category
- JavaScript
- Title
- javascript ceiling
- Category
- JavaScript
- Title
- Getting the differences between two objects javascript lib
- Category
- JavaScript
- Title
- font awesome 4.7 cdn
- Category
- JavaScript
- Title
- angularjs
- Category
- JavaScript
- Title
- conditional rendering in react
- Category
- JavaScript
- Title
- Javascript change element class
- Category
- JavaScript
- Title
- conditional jsx property
- Category
- JavaScript
- Title
- how to host react app on heroku
- Category
- JavaScript
- Title
- javascript change class of item
- Category
- JavaScript
- Title
- dynsmic calss in react add
- Category
- JavaScript
- Title
- how to remove spaces from strings javascript
- Category
- JavaScript
- Title
- how to make fake binary
- Category
- JavaScript
- Title
- change innertext javascript
- Category
- JavaScript
- Title
- arrow function in javascript w3schools
- Category
- JavaScript
- Title
- how to check if variable is array in js
- Category
- JavaScript
- Title
- electron jquery
- Category
- JavaScript
- Title
- is sublime text a good editor
- Category
- JavaScript
- Title
- Exception in thread "main" org.openqa.selenium.JavascriptException:
- Category
- JavaScript
- Title
- adonisjs livereload
- Category
- JavaScript
- Title
- find last item in an array JS
- Category
- JavaScript
- Title
- error Invalid regular expression: /(.*\\__fixtures__\\.*|node_modules[\\\]react[\\\]dist[\\\].*|website\\node_modules\\.*|heapCapture\\bundle\.js|.*\\__tests__\\.*)$/: Unterminated character class.
- Category
- JavaScript
- Title
- installing vue router & implementation
- Category
- JavaScript
- Title
- check a checkbox jquery
- Category
- JavaScript
- Title
- how to add changes every time you route navigate to page in angular
- Category
- JavaScript
- Title
- convert an image into Base64 string using JavaScript
- Category
- JavaScript
- Title
- javascript classes
- Category
- JavaScript
- Title
- javascript check for duplicates in array
- Category
- JavaScript
- Title
- bookshelf insert multiple rows
- Category
- JavaScript
- Title
- how to loop over dom objects javascript
- Category
- JavaScript
- Title
- express js sample project
- Category
- JavaScript
- Title
- get image file width javascript
- Category
- JavaScript