class name acess?

Discussion in 'Javascript' started by Sergio del Amo Caballero, Oct 23, 2003.

  1. 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.
     
    Sergio del Amo Caballero, Oct 23, 2003
    #1
    1. Advertisements

  2. Sergio del Amo Caballero <> writes:

    > 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
    --
    Lasse Reichstein Nielsen -
    DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
    'Faith without judgement merely degrades the spirit divine.'
     
    Lasse Reichstein Nielsen, Oct 23, 2003
    #2
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. James
    Replies:
    2
    Views:
    453
    James
    Apr 29, 2005
  2. E11
    Replies:
    1
    Views:
    5,782
    Thomas Weidenfeller
    Oct 12, 2005
  3. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    1,159
    Roedy Green
    Jan 2, 2006
  4. ding feng
    Replies:
    2
    Views:
    3,291
    ding feng
    Jun 25, 2003
  5. Bobby Chamness
    Replies:
    2
    Views:
    2,632
    Joe Smith
    Apr 22, 2007
  6. Jack-2
    Replies:
    3
    Views:
    621
    Jack-2
    Dec 24, 2003
  7. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    517
    Java script Dude
    Jun 30, 2004
  8. Yakov
    Replies:
    1
    Views:
    221
    John W. Krahn
    Nov 12, 2006
Loading...