Dave's Brain

Browse - Programming Tips - How do I alternately show and hide an HTML element?

Date: 2014dec6
Library: jQuery

Q.  How do I alternately show and hide an HTML element?

A.  Use jQuery's toggle like this:

<button type=button id=mybutton>Toggle</button> <div id=mything>Hello</div> <script src=jquery.js></script> <script> $('#mybutton').click(function() { $('#mything').toggle(); }); </script>

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.