Show and hide div onclick button

Zoker picture Zoker · Dec 11, 2013 · Viewed 49.5k times · Source

How can I show and hide a div (content) with a click on a button?

Here some code:

<button class="btn btn-default">Text</button>
<div class="div-to-hide">Some content</div>

Answer

cantonic picture cantonic · Dec 12, 2013

You can do this by using jQuery's toggle function like <button class="button" onclick="$('#target').toggle();">Show/Hide</button>

Here is a working example: http://jsfiddle.net/W2vh3/