In your html file:
<a href="#" id="show_whatever">Show Whatever</a> <div id="whatever" class="hidden">...</div>
In your CSS file:
div.hidden { display: none; }
In the included javascript file or in the <script>
tags:
$(function() { $('a#show_whatever').click(function(event){ event.preventDefault(); $('div#whatever').toggle(); }); });
The hidden
class hides the div. The jQuery function searches for a click on the link and then prevents the link from being tracked ( event.preventDefault()
saves it from viewing to #
), and finally switches the visibility of the div.
See the jQuery API for click () and toggle () .
source share