SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Making a div appear and disappear

    This makes my div appear (when the display attribute is set to none) using the onclick event:
    Code:
    divTest = document.getElementById('linkContainer2');
    if (divTest.style.display === "none") {
            divTest.style.display = '';
    }
    I thought this would make it appear and disappear (depending on the display attribute) using the onclick event, but it doesn't. Why?
    Code:
    divTest = document.getElementById('linkContainer2');
    if (divTest.style.display === "none") {
                    divTest.style.display = '';
             } elseif (divTest.style.display === "") {
                     divTest.style.display = "none";
            }

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    Well, the first thing I did was change your "elseif" to "else if" (notice the space) and that got it to work immediately. However, I would also recommend using 'block' instead of '' in "divTest.style.display = '';" and remove the if condition in the else statement as shown at http://jsfiddle.net/cpradio/mYDN9/

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks cpradio. Is JSfiddle your site?

  4. #4
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,073
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    No, I wish I had the creativity to create that, I am just a user of it. It makes answering forum questions very simple

  5. #5
    SitePoint Evangelist
    Join Date
    Jun 2010
    Posts
    453
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Just wondered since it's an alpha.

    By the way, thanks again.


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
  •