Imagine having 5 div elements, each with a similar onclick-function that hides the other divs when clicked.
HTML:
<div id="1" class="divs" onclick="hide()"></div>
<div id="2" class="divs" onclick="hide()"></div>
<div id="3" class="divs" onclick="hide()"></div>
<div id="4" class="divs" onclick="hide()"></div>
<div id="5" class="divs" onclick="hide()"></div>
This is what has been attempted:
JavaScript:
function hide(){
var divs = document.getElementsByClassName("divs");
for(var i = 0; i < arrows.length; i++){
if(this != arrows[i]){
arrows[i].style.display = "none";
}
}
}
The current outcome results in all divs being hidden, rather than just leaving the clicked element visible. Looking to achieve this using vanilla JS instead of jQuery's ":not()" selector. Any tips?
Appreciate any help provided.