Mancent Posted November 28, 2012 Share Posted November 28, 2012 (edited) Hi I have this div tag name id one and id two and I can get teh div tag to open to show the div tag two, but i can not get it to close. heres what I got! If you look on my page http://wiistream.com you will see a please help button at the top, and if you click it it opens the donations panel! what i want to do is, if you click the please help button again make it close the donation panel. button: <span class="btn4" onclick="javascript:showDiv();"><a href="#"></a></span> JS <script type="text/javascript"> function showDiv() { div = document.getElementById('two'); div.style.display = "block"; } function hideDiv() { div = document.getElementById('two'); div.style.display = "none"; } </script> Any ideas how to do this? im new to JS i thought I could make a simple switch's function in the JS script. that the button calls and have if statement of some sort! function hideDiv_And_showDiv() { if(SOMETHING?) { div = document.getElementById('two'); div.style.display = "none"; } else { div = document.getElementById('two'); div.style.display = "block"; } } Edited November 28, 2012 by Mancent Quote Link to comment https://forums.phpfreaks.com/topic/271305-open-and-close-div-tag-with-button-help/ Share on other sites More sharing options...
Mancent Posted November 28, 2012 Author Share Posted November 28, 2012 function showDiv_And_hideDiv() { if(document.getElementById('two').style.display=='block') { div = document.getElementById('two'); div.style.display = "none"; } else { div = document.getElementById('two'); div.style.display = "block"; } } NVM Got it! Quote Link to comment https://forums.phpfreaks.com/topic/271305-open-and-close-div-tag-with-button-help/#findComment-1395968 Share on other sites More sharing options...
codefossa Posted November 28, 2012 Share Posted November 28, 2012 If you used jQuery it would simply be $("#two").toggle(); Just a suggestion. jQuery can help shorten a lot of code, as well as make it compatible with the top browsers without extra coding for each. Quote Link to comment https://forums.phpfreaks.com/topic/271305-open-and-close-div-tag-with-button-help/#findComment-1395984 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.