I'm trying to make a code that sorts divs based on their class names, with buttons that toggle show(); if the class exists but hide(); if the class does not exist. I'm not getting any errors but the code doesn't want to work the way I think I've told it to? When you click the button in my preview it hides the id that has the class name and does nothing to the ones that don't.
CSS
<html> <head> <title>Sorting</title> <link rel="stylesheet" type="text/css" href="assets/css/style.css"> <script type="text/javascript" src="assets/js/jquery.js"></script> <script type="text/javascript" src="assets/js/jquery-ui.js"></script> </head> <body> <div id="sort-box"><div id="button-wrap"> <button id="everyone" class="sort-button active">everyone</button> <button id="lions" class="sort-button">lions</button> <button id="tigers" class="sort-button">tigers</button> <button id="bears" class="sort-button">bears</button> <textarea id="search" class="sort-button" placeholder="search"></textarea></div> <div class="sort-hold"> <div id="member" class="lions all">member name - lion</div> <div id="member" class="tigers all">member name - tiger</div> <div id="member" class="bears all">member name - bear</div> </div> </div> <script type="text/javascript" src="assets/js/main.js"></script> </body> </html>
JS
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(); }; $("#lions").click(sortOne); function sortOne() { console.log("button clicked!") if($("#member").hasClass(".lions")){ $("#member").show(); } else { $("#member").hide(); } };