making multiple elements visible

Discussion in 'Javascript' started by libsfan01, Jul 27, 2006.

  1. libsfan01

    libsfan01 Guest

    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
     
    libsfan01, Jul 27, 2006
    #1
    1. Advertising

  2. libsfan01

    Randy Webb Guest

    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/
     
    Randy Webb, Jul 27, 2006
    #2
    1. Advertising

  3. libsfan01

    libsfan01 Guest

    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/
     
    libsfan01, Jul 28, 2006
    #3
    1. Advertising

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. spamfurnace
    Replies:
    1
    Views:
    2,636
    Scott M.
    May 24, 2004
  2. tshad

    button visible/not visible

    tshad, Oct 26, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    4,449
    Brian Hoops
    Oct 28, 2004
  3. tshad

    Sections visible and not visible

    tshad, Jan 31, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    2,064
    tshad
    Jan 31, 2005
  4. Patrick Olurotimi Ige
    Replies:
    7
    Views:
    5,972
    Patrick Olurotimi Ige
    Jun 15, 2005
  5. Daniel Berger
    Replies:
    2
    Views:
    94
    Daniel Berger
    Feb 25, 2010
Loading...

Share This Page