Check out this code snippet :
function ToggleMenu() {
var v = $("#MenuVisibility").val() ;
if (v == "1") {
$('#MenuVisibility').val("0");
}
else {
$('#MenuVisibility').val("1");
}
v = $("#MenuVisibility").val();
alert(v);
}
</script>
<title></title>
</head>
<body>
<input type="hidden" value="1" id="MenuVisibility" />
<form id="form1" runat="server">
<div id="Menu">
<a class="MainMenu" href="#" onclick="OpenCloseMenu()">Exciting Stuff</a>
<div id="ExtendedMenu">
<ul>
<li><a href="#">Item 1</a></li>
<li><a href="#">Item 2</a></li>
<li><a href="#">Item 3</a></li>
<li><a href="#">Item 4</a></li>
<li><a href="#">Item 5</a></li>
</ul>
</div>
</div>
<asp:Button ID="Button1" runat='server' Text="Toggle Menu" OnClientClick="ToggleMenu()" />
</form>
</body>
</html>
After clicking the button for the first time, the hidden field's value changes to 0. However, upon clicking for the second time, the value does not switch back to 1. Why could this be happening?