class name acess?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sergio del Amo Caballero

    class name acess?

    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.cl assName 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.get ElementsByTagNa me("div")[i].className == "node1")
    document.getEle mentsByTagName( "div")[i].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.


  • Lasse Reichstein Nielsen

    #2
    Re: class name acess?

    Sergio del Amo Caballero <sergi@sbox.tug raz.at> writes:
    [color=blue]
    > I want to access div elemnent and make them visible or invisible with
    > a condition. They belong to a particular class or not.[/color]
    [color=blue]
    > if(document.get ElementsByTagNa me("div")[i].className == "node1")
    > document.getEle mentsByTagName( "div")[i].style.display= "none";[/color]

    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.getEle mentsByTagName( "div");
    for (var i=0 ; i<divs.length ; i++) {
    if (divs[i].className == "node1") {
    divs[i].style.display = "none";
    }
    }
    [color=blue]
    > I know that the line in the if is in correct. Anybody know how to
    > implent this to work in the browsers above.[/color]

    It should work in the above browsers.

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...