Let's say I have 5 div elements. They all have a similar onclick function that will “delete” other divs except for the clicked div.
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>
So here is what I tried:
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";
}
}
}
All this does is remove each div, but the element with the click should remain. I know there is a ": not ()" selector in jQuery, but I want to do this using JS. Any suggestions?
thank
source
share