niche Posted May 17, 2012 Share Posted May 17, 2012 (edited) 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"; } Edited May 17, 2012 by niche Link to comment Share on other sites More sharing options...
Guest So Called Posted May 17, 2012 Share Posted May 17, 2012 (edited) (deleted - wrong answer) Edited May 17, 2012 by So Called Link to comment Share on other sites More sharing options...
dsonesuk Posted May 17, 2012 Share Posted May 17, 2012 elseif else if 1 Link to comment Share on other sites More sharing options...
Guest So Called Posted May 17, 2012 Share Posted May 17, 2012 (edited) (deleted - also wrong) Edited May 17, 2012 by So Called Link to comment Share on other sites More sharing options...
justsomeguy Posted May 17, 2012 Share Posted May 17, 2012 If you change that elseif to else if and it still doesn't work, then the display is set to neither 'none' nor ''. 1 Link to comment Share on other sites More sharing options...
niche Posted May 17, 2012 Author Share Posted May 17, 2012 That was it. For everything there is a first time. I didn't have that distinction in my head until now. Thanks again dsonesuk and for your effort So Called. Also, I appreciate your comment justsomeguy. That probably wouldn't have occurred to me. Link to comment Share on other sites More sharing options...
Guest So Called Posted May 17, 2012 Share Posted May 17, 2012 YWVM... I write too much PHP and didn't realize that PHP's elseif doesn't go for JS. So I learned something too. Link to comment Share on other sites More sharing options...
niche Posted May 17, 2012 Author Share Posted May 17, 2012 Both of us get to do better now that we know better! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now