Jump to content

Recommended Posts

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 by Mancent
Link to comment
https://forums.phpfreaks.com/topic/271305-open-and-close-div-tag-with-button-help/
Share on other sites

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.