Easier way to hide multiple spans/divs?

J

Joe Black

I have a js script that changes the visibilty of a selected span to
"visible", but makes sure that no other related spans are visibile to
the user by hiding everything first.

i.e. User clicks on link for 'Box1' ->

document.getElementById("box1").style.visibility="hidden";
document.getElementById("box2").style.visibility="hidden";
document.getElementById("box3").style.visibility="hidden";
document.getElementById("box4").style.visibility="hidden";
document.getElementById("box5").style.visibility="hidden";
document.getElementById("box1").style.visibility="visible";
...

is there an easier way to refer to *all* of the spans that need to be
hidden, preferably in one/two lines of code?
 
F

Fox

Joe said:
I have a js script that changes the visibilty of a selected span to
"visible", but makes sure that no other related spans are visibile to
the user by hiding everything first.

i.e. User clicks on link for 'Box1' ->

document.getElementById("box1").style.visibility="hidden";
document.getElementById("box2").style.visibility="hidden";
document.getElementById("box3").style.visibility="hidden";
document.getElementById("box4").style.visibility="hidden";
document.getElementById("box5").style.visibility="hidden";
document.getElementById("box1").style.visibility="visible";
...

is there an easier way to refer to *all* of the spans that need to be
hidden, preferably in one/two lines of code?

for(var i = 1; i <= 5; i++)
document.getElementById("box" + i).style.visibility = "hidden";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top