How do I create a show and hide button in javaScript where it leaves the contents already hidden when I open the page? I just click first to show and then to hide.
How do I create a show and hide button in javaScript where it leaves the contents already hidden when I open the page? I just click first to show and then to hide.
I think this is what you want:
hide () hides the div when the page finishes loading. Toggle () is triggered by the button displaying and hiding the div
<html>
<head runat="server">
<title></title>
</head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script><scripttype="text/javascript">
$(document).ready(function (e) {
$("#divConteudo").hide();
$("#btnMostrarEsconder").click(function (e) {
$("#divConteudo").toggle();
});
});
</script>
<body>
<div id="divConteudo">
Conteudo
</div>
<button id="btnMostrarEsconder" type="button">Mostrar e Esconder</button>
</body>
</html>