468,101 Members | 1,420 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,101 developers. It's quick & easy.

Easier way to hide multiple spans/divs?

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?
Jul 20 '05 #1
1 4719
Fox


Joe Black wrote:

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";
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

12 posts views Thread by Jochen Daum | last post: by
27 posts views Thread by Nicholas Couch | last post: by
5 posts views Thread by dje | last post: by
4 posts views Thread by bridgemanusa | last post: by
5 posts views Thread by ali | last post: by
1 post views Thread by Solo | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.