I have many div with the class name dis
HTML:
<div class="dis">Content</div>
<div class="dis">Content</div>
<div class="dis">Content</div> and so on ...
And have many images:
<img src="icons/image1.png" class="admoicn" onclick="toggle_visibility('dis');" >
<img src="icons/image2.png" class="admoicn" onclick="toggle_visibility('dis');" >
<img src="icons/image3.png" class="admoicn" onclick="toggle_visibility('dis');" >
CSS:
.dis{
display:none;
width:100px;
height:100px;
}
javascript:
function toggle_visibility(id) {
var e = document.getElementsByClassName(id)[0];
if(e.style.display =="block"){
e.style.display ="none";
}
else{
e.style.display ="block";
}
}
Onclicking any image the specific div dis should be open, I mean onclicking third image3.png the third number of div dis should be open and close all opened dis div.
I think it's the array problem on javascript class and I don't know how to fix it. I'm very new to javascript.
diselements have no other siblings, and same for the images. But we shouldn't be guessing at details like this.