class name acess?

  • Thread starter Sergio del Amo Caballero
  • Start date
S

Sergio del Amo Caballero

I want to access div elemnent and make them visible or invisible with a
condition. They belong to a particular class or not. I was reading the
newsgroup old posting about classname acess and some links and i arrived
to the conclusion that i can not access class Name with Mozilla. With
Explorer i can acesss with document.all.className but i want visualize
my web site in Opera 7.2, Mozilla 1.4 and Explorer 6.0. My code will be
something like this:

if(document.getElementsByTagName("div").className == "node1")
document.getElementsByTagName("div").style.display="none";


I know that the line in the if is in correct. Anybody know how to
implent this to work in the browsers above.
 
L

Lasse Reichstein Nielsen

Sergio del Amo Caballero said:
I want to access div elemnent and make them visible or invisible with
a condition. They belong to a particular class or not.
if(document.getElementsByTagName("div").className == "node1")
document.getElementsByTagName("div").style.display="none";


What is "i"?

If I understand the problem correctly, and I am not sure I do, you will
need something like this:

var divs = document.getElementsByTagName("div");
for (var i=0 ; i<divs.length ; i++) {
if (divs.className == "node1") {
divs.style.display = "none";
}
}
I know that the line in the if is in correct. Anybody know how to
implent this to work in the browsers above.

It should work in the above browsers.

/L
 

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

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top