Show / Hide button [duplicate]

-3

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.

    
asked by anonymous 13.11.2015 / 18:33

1 answer

0

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>
    
13.11.2015 / 19:04