SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    May 2002
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Post Automatic Showing/Hiding of Divs

    Hey guys, I'm trying to figure out the least-sloppy(always a good thing in my opinion) way of doing the code for this...

    I've got a half dozen hyperlinks that I want to use to show content in the center of a page. I've got a half dozen div windows with the content in them, all hidden. What's the best way to create a function to check the passed id of the link and show only the passed link's div while hiding the rest?

    The best method in my mind so far is to load all the div names into an array and pass it through a loop to check the visibility and hide them all as necessary, and right after the end of the loop, do a show command and pass the id of the chosen div.

    Any other suggestions?

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes - i wouldn't use the array.

    Just use a variable called "current" to denote the currently showing div.

    then use something like:

    Code:
    // href examples:
    a href="#" onclick="swtich('Biking');return false"
    a href="#" onclick="swtich('Shooting');return false"
    
    // div examples:
    div name="Biking_div" id="Biking_div" style="display:none"
    div name="Shooting_div" id="Shooting_div" style="display:none"
    
    var current;
    function switchDivs(cont){
      if (current) de(current+'_div').style.display='none';
      current=cont;
      de(current+'_div').style.display='';
      }
    I hope this helps

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •