/    Sign up×
Community /Pin to ProfileBookmark

Script not showing and hiding as expected

Hi Everyone,

I have written a very small page (and accompanying script) to test the visibility altering behaviour of IE. I am trying to hide or show a <div> element, alternatively based upon a button being pressed. The code does not work as I had hoped, hence why I am posting. If anybody can provide some pointers as to how I might be able to get this code going I will be very appreciative. Thanks heaps.

Regards

Davo

<html>
<head>
<title> Experimenting with toggling element visibility </title>
<style type=”text/css”>
#box
{
background-color: #00ff00;
left: 50px;
height: 100px;
position: absolute;
top: 50px;
width: 100px;
}
#place_button
{
left: 100px;
position: absolute;
top: 300px;
}
</style>
<script type=”text/javascript”>

var visibile = true;

function toggleMenu()
{
if(visibile == false)
{
document.getElementById(“box”).visiblity = “show”;
visibile = true;
}
else
if(visibile == true)
{
document.getElementById(“box”).visibility = “hidden”;
visibile = false;
}
}
</script>
</head>
<body>
<div id=”box”>
<form>
<input id=”place_button” type=”button” value=”Click This” onclick=”toggleMenu()”>
</form>
</div>
</body>
</html>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@DirectrixJul 12.2004 — Just change the function:
[CODE]
function toggleMenu()
{
if(visibile == false)
{
document.getElementById("box").style.visibility = "visible";
visibile = true;
}
else
if(visibile == true)
{
document.getElementById("box").style.visibility = "hidden";
visibile = false;
}
}
[/CODE]
Copy linkTweet thisAlerts:
@cootheadJul 12.2004 — Hi there 3D_Dog_Man,

in addition to what Directrix has said you need to change ...
&lt;body&gt;
&lt;div id="box"&gt;
&lt;form&gt;
&lt;input id="place_button" type="button" value="Click This" onclick="toggleMenu()"&gt;
&lt;/form&gt;[color=red]
&lt;/div&gt;[/color]
&lt;/body&gt;

to...&lt;body&gt;
&lt;div id="box"&gt;[color=red]&lt;/div&gt;[/color]
&lt;form&gt;
&lt;input id="place_button" type="button" value="Click This" onclick="toggleMenu()"&gt;
&lt;/form&gt;

&lt;/body&gt;

...or your button will disappear on the first click ?

[i]coothead[/i]
×

Success!

Help @3D_Dog_Man spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...