Jump to content

Show/Hide Div


Dysan

Recommended Posts

Using JavaScript, how do I show/hide a div, upon clicking the appropriate button?

 

<html>
<head>
<title></title>
</head>

<body>
<form name="form1" method="post" action="">
  <input type="submit" name="Submit" value="Show">
  <input type="submit" name="Submit2" value="Hide">
</form>
</body>
</html>

Link to comment
Share on other sites

<html>
<head>
<title></title>
</head>

<body>
  <input type="button" name="Submit" value="Show" onclick="javascript:document.getElementById('thehidden1').style.display='block'; return true">
  <input type="button" name="Submit2" value="Hide" onclick="javascript:document.getElementById('thehidden1').style.display='none'; return true">
<div id="thehidden1" style="width:300px;height:225px;border:solid 1px black;display:none">

</div>
</body>
</html>

Link to comment
Share on other sites

<html>
<head>
<title></title>

<script language="javascript">
function showIt()
{
document.getElementById('thehidden1').style.display='block';
}
function hideIt()
{
document.getElementById('thehidden1').style.display='none';
}
</script>

</head>

<body>
  <input type="button" name="Submit" value="Show" onclick="showIt()">
  <input type="button" name="Submit2" value="Hide" onclick="hideIt()">
<div id="thehidden1" style="width:300px;height:225px;border:solid 1px black;display:none">

</div>
</body>
</html>

Link to comment
Share on other sites

  • 1 month later...

<html>
<head>
<title></title>
</head>

<body>
  <input type="button" name="Submit" value="Show" onclick="javascript:document.getElementById('thehidden1').style.display='block'; return true">
  <input type="button" name="Submit2" value="Hide" onclick="javascript:document.getElementById('thehidden1').style.display='none'; return true">
<div id="thehidden1" style="width:300px;height:225px;border:solid 1px black;display:none">

</div>
</body>
</html>

 

I changed this code to use <a href=""> tags:

 

<?php
<a href="" onclick="javascript:document.getElementById('thehidden1').style.display='block'; return true">show</a>
<a href="" onclick="javascript:document.getElementById('thehidden1').style.display='none'; return true">hide</a>
<div id="thehidden1" style="width:300px;height:225px;border:solid 1px black;display:none;">
<p>CAN WE SEE THE WIBBLES?</p>
</div>
?>

 

but the division only shows for a split second. Could you please advise what I need to change to make the display:block permenant until the "hide" link is clicked?

 

Many thanks as always,

 

James.

Link to comment
Share on other sites

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.