SitePoint Sponsor

User Tag List

Results 1 to 6 of 6

Thread: hide div...

  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    hide div...

    I am a non-scripter with a question...

    using this js:
    function toggle( targetId ){
    if (document.getElementById){
    target = document.getElementById( targetId );
    if (target.style.display == "none"){
    target.style.display = "";
    } else {
    target.style.display = "none";
    }
    }
    }


    I am trying to figure out how to make this show and hide divs based on their ID... basically I want it to show the element that I've clicked on and Hide any others that might be visible.

    thanks.

  2. #2
    ♪♪ ♪ ♪ ♪ ♪♪ ♪ ♪♪ Markdidj's Avatar
    Join Date
    Sep 2002
    Location
    Bournemouth, South UK
    Posts
    1,551
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    hidden or inline are the two syntax's you need I think
    LiveScript: Putting the "Live" Back into JavaScript
    if live output_as_javascript else output_as_html end if

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry but i don;t understand.
    I'm hoping keep this script's main functionality, but i want to add the ability to close all other 'opn' and visible divs.
    thanks.

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    that should be 'open'

  5. #5
    SitePoint Guru Vincent Puglia's Avatar
    Join Date
    Feb 2000
    Location
    where the World once stood
    Posts
    700
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    You would need to do 2 things:
    1) name your divs consecutively -- myDiv0, myDiv1...
    2) use a loop to set the display

    if you posted some html, so we can see what your divs look like, a better and/or more specific solution might be forthcoming.

    Vinny
    Where the World Once Stood
    the blades of grass
    cut me still

  6. #6
    SitePoint Enthusiast
    Join Date
    Jun 2002
    Posts
    69
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The related html looks like this:
    <div id="button"><a href="#" onclick="toggle('intro');return false;"><img src="img.gif" alt="Open" width="15" height="15" /></a></div>
    <div id="intro" style="display:none"><p>Text</p></div>

    <div id="button2"><a href="#" onclick="toggle('more');return false;"><img src="img.gif" alt="Open2" width="15" height="15" /></a></div>
    <div id="more" style="display:none"><p>Text</p></div>

    the divs are positioned absolutly. there are multiple divs treated like this - all with different IDs.

    ideally when i open "intro" it will check to make sure that "more" or any other DIV is set to display:none

    i hop ethis makes sense.

    thanks.


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
  •