469,293 Members | 1,319 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

making multiple elements visible

hi!

i have written a function to make visible elements with a certain id.
however i intended it to be used to make visible multiple elements but
it only appears to switch on the first element it comes to with that
id. after that it appears to stop. i was wondering how i can adapt this
function to make visible multiple elements, will i need a different way
of referencing or can it be done through id?

your thoughts are greatly appreciated on this...
function toggleLayer( layerID ) {

var style2 = document.getElementById( layerID );
if (style2.style.display == "block") {
style2.style.display = "none";
}
else {
style2.style.display = "block";
}

}
kind regards

marc

Jul 27 '06 #1
2 1564
libsfan01 said the following on 7/27/2006 5:02 PM:
hi!

i have written a function to make visible elements with a certain id.
however i intended it to be used to make visible multiple elements but
it only appears to switch on the first element it comes to with that
id.
Since ID attributes have to be unique in a document then the behavior
you describe is what it should do.
after that it appears to stop. i was wondering how i can adapt this
function to make visible multiple elements, will i need a different way
of referencing or can it be done through id?
Give your elements a class name and then change the CSS of that class.
Or, change the className of any divs that you want changed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 27 '06 #2
Thanks Randy.

Can anyone tell me the best way to get elements by classname?
Kind regards

Marc

Randy Webb wrote:
libsfan01 said the following on 7/27/2006 5:02 PM:
hi!

i have written a function to make visible elements with a certain id.
however i intended it to be used to make visible multiple elements but
it only appears to switch on the first element it comes to with that
id.

Since ID attributes have to be unique in a document then the behavior
you describe is what it should do.
after that it appears to stop. i was wondering how i can adapt this
function to make visible multiple elements, will i need a different way
of referencing or can it be done through id?

Give your elements a class name and then change the CSS of that class.
Or, change the className of any divs that you want changed.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Jul 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.