How using javascript to hide all blocks from one class except one?

0 like 0 dislike
7 views
Is there a list of stores and need to by clicking on a certain store has a window with a description, and clicking on another before the open window closed.
How it can be implemented via Javascript?
Now there is here such code, which opens a box when you click on the link and when pressed again closes:
function openbox(id){ display = document.getElementById(id).style.display; if(display=='none'){ document.getElementById(id).style.display='block'; }else{ document.getElementById(id).style.display='none'; } }

Is it possible first set of all closure blocks with a specific class, and then opening the desired id? I think this would be conceived. Or maybe there is a better option?
by | 7 views

1 Answer

0 like 0 dislike
\r\r\r\ritem 1\ritem 2\ritem 3


function openbox(id){ var el = document.getElementById('item'+id); if(el.hidden){ document.querySelectorAll('.item').forEach(item => item.hidden = true); el.hidden = false; }else{ el.hidden = true; } }


\rhttps://jsfiddle.net/utzr8edr/

.
by

Related questions

0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,863 users