SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Easy question

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Easy question

    Using the code below to allow certain elements of a page to will hidden and expanded by the click of a button. They are all expanded by default, but how do I make something hidden by default with this code?

    Thanks in advance.

    Code:
    function contract(id) 
    { 
        if (document.getElementById(id).style.display=='none') 
        { 
            document.getElementById(id).style.display='block'; 
        } 
        else 
        { 
            document.getElementById(id).style.display='none'; 
        } 
    }

  2. #2
    SitePoint Evangelist Mr. Brownstone's Avatar
    Join Date
    May 2002
    Location
    Relative
    Posts
    452
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It looks to me like you donít need to change the JavaScript itself. Just apply the display: none; CSS style to any element you want hidden when the page loads:
    HTML Code:
    <a href="#" onclick="contract(someDiv);">Show/Hide</a>
     
     <div id="someDiv" style="display: none;"> (blah) </div>
    Of course, that's just my opinion. I could be wrong.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2003
    Location
    Leeuwarden
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the help! Nice and easy. ~


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
  •