Making a div appear and disappear

This makes my div appear (when the display attribute is set to none) using the onclick event:

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?

divTest = document.getElementById('linkContainer2');
if (divTest.style.display === "none") {
                divTest.style.display = '';
         } elseif (divTest.style.display === "") {
                 divTest.style.display = "none";
        }

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/

Thanks cpradio. Is JSfiddle your site?

No, I wish I had the creativity to create that, I am just a user of it. It makes answering forum questions very simple :slight_smile:

Just wondered since it’s an alpha.

By the way, thanks again.