Im trying to toggle the div to make it visible/hidden. Im making a leader board of sorts that i want to open but only when clicked.
<html>
<title>test</title>
<head>
<script type="text/javascript">
<!-- the function -->
function showleaders() {
if (document.getElementById('leaderboard').style.visibility = "hidden";) {
document.getElementById('leaderboard').style.visibility = "visible";
} else {
document.getElementById('leaderboard').style.visibility = "hidden";
}
}
</script>
<style type="text/css">
#leaderboard {
height: 300px;
width:300px;
left:0;
background:red;
border-radius:20%;
visibility:hidden;
}
</style>
</head>
<body>
<a href="javascript:showleaders();">Leaderboard</a>
<div id="leaderboard">hello</div>
</body>
</html>
What am i doing wrong?
I just want the div to toggle in between visibilities
You need to change the equals sign in this line:
To a double equals, and remove the semicolon. Try this:
A single equals sets the value, a double equals compares the value.