filterSelection("all")
function filterSelection(c) {
var x, i;
x = document.getElementsByClassName("filterDiv");
if (c == "all") c = "";
for (i = 0; i < x.length; i++) {
w3RemoveClass(x[i], "show");
if (x[i].className.indexOf(c) > -1) w3AddClass(x[i], "show");
}
}
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];}
}
}
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 button (highlight it)
var btnContainer = $document.getElementById("buttonContainer");
var buttons = btnContainer.getElementsByClassName("searchButton");
for (var i = 0; i < buttons.length; i++) {
buttons[i].addEventListener("click", function(){
var current = document.getElementsByClassName("currentActive");
current[0].className = current[0].className.replace(" currentActive", "");
this.className += " currentActive";
});
}
.filterDiv {
float: left;
margin: 2px;
display: none;
}
.searchButton
{
list-style: none;
display: inline-block;
}
.show {
display: block;
}
.section {
margin-top: 20px;
overflow: hidden;
}
/* Style the buttons */
.btn {
border: none;
outline: none;
padding: 12px 16px;
cursor: pointer;
}
/* animation duration */
#animation
{
animation-duration: 2s;
}
#buttonContainer
{
display: flex;
overflow-x: auto;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8>;
<meta http-equiv="X-UA-Compatible" content="IE=edge>;
<meta name="viewport" content="width=device-width, initial-scale=1.0">;
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">;
<title>Document</title>;
</head>;
<body>;
<h2>Example</h2>;
<div id="buttonContainer">;
<li class="searchButton currentActive" onclick="filterSelection('all')"> Show all</li>;
<li class="searchButton" onclick="filterSelection('sam')"> sam</li>;
<li class="searchButton" onclick="filterSelection('john')"> john</li>;
<li class="searchButton" onclick="filterSelection('rog')"> rog</li>;
<li class="searchButton" onclick="filterSelection('stv')"> stv</li>;
<li class="searchButton" onclick="filterSelection('scott')"> scott</li>;
</div>;
<div class="section">;
<div class="filterDiv all w3-container w3-animate-bottom" id="animation">;
<h4>What is food?</h4>;
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
<h4>lorem ipsum</h4>;
<p> lorem ipsum
</p>;
<h4>lorem ipsum</h4>;
<p class="text"> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
</div>;
<div class="filterDiv sam w3-container w3-animate-bottom" id="animation">;
<h4>lorem ipsum</h4>;
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
<h4 >What is the Cricket Live Scores API?</h4>;
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t
</p>;
</div>;
<div class="filterDiv john w3-container w3-animate-bottom" id="animation">;
<h4>lorem ipsum</h4>;
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
<h4>lorem ipsum</h4>;
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
</div>;
<div class="filterDiv rog w3-container w3-animate-bottom" id="animation">;
<h4>lorem ipsum</h4>;
<p> Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
</div>;
<div class="filterDiv stv w3-container w3-animate-bottom" id="animation">;
<h4>lorem ipsum</a></h4>;
<p class="text">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Cum omnis architecto laborum nam t</p>;
</div>;
</div>;
</body>;
</html>
;
https://i.sstatic.net/ydKeC.jpg
The provided image was captured on my mobile phone.
- I am seeking guidance on removing the blue color that appears in the background when clicking on any of the list tags. The color was not added through CSS.
- I attempted using focus and active in my CSS but had no success.
- I aim to achieve a similar layout as depicted in the following picture.
https://i.sstatic.net/qGecb.jpg
While exploring W3Schools, I came across data filtering examples which inspired me to try one myself. However, I am facing a challenge with understanding the source of the blue color visible in the images.