Sunday, May 13, 2012

jQuery: Show or Hide an Element on Click

To show or hide an element when use click on a button, you can use jQuery's .toggle() method. It toggles the display of that node. It adds a style display: none; and display: block alternatively, with each click.
//listen for the button click event
$('.myElemBtn').on('click', function (e) {
$('.myElem').toggle(); // toggle visibility