making multiple elements visible

L

libsfan01

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
 
R

Randy Webb

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.
 
L

libsfan01

Thanks Randy.

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

Marc
 

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
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top