Add class everyone to everyone btn and replace sort-hold member to class name instead of id
Fix #member to be .member
#sort-box {
width: 100%;
}
#button-wrap {
width: 100%;
display: flex;
}
.sort-button {
flex: 1;
margin-right: 10px;
width: 100%;
display: block;
border: none;
background: #eee;
outline: none;
border-radius: none;
height: 40px;
resize: none;
text-align: center;
font-family: arial;
font-size: 10px;
line-height: 40px;
text-transform: uppercase;
}
.active,
.sort-button:hover {
background: #fde676;
}
#search {
margin-right: 0px;
text-align: left;
padding: 0px 10px;
flex: 1.5;
}
.sort-hold {
width: 100%;
background: #eee;
margin-top: 10px;
padding: 5px 0px;
}
.member {
margin: 10px;
width: calc(100% - 70px);
height: 50px;
line-height: 50px;
padding: 0px 25px;
text-transform: uppercase;
font-family: arial;
background: #fff;
font-size: 10px;
outline: 1px solid #ddd;
outline-offset: -1px;
}
// Get the container element
var btnWrap = document.getElementById("button-wrap");
// Get all buttons with class="btn" inside the container
var btns = btnWrap.getElementsByClassName("sort-button");
// Loop through the buttons and add the active class to the current/clicked button
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";
});
}
$("#everyone").click(sortEveryone);
function sortEveryone() {
console.log("button clicked!")
$(".member").show();
}
// add activeBtn function for all btns except .everyone
for (var btn of btns) {
$(btn).hasClass("everyone") == false ? btn.addEventListener("click", activeBtn) : "";
}
function activeBtn(e) {
let targetId = e.target.id;
let members = $(".member");
// if the member class has the same name as the btn id, show it else hide it
for (var member of members) {
$(member).hasClass(targetId) ? $(member).show() : $(member).hide();
}
}
And I have addadded .everyone for everyone btn to make it more easier to handelhandle.