I am using a code that unhides a hidden div.
HTML:
JavaScript
x
4
1
<div id="unhide" style="display:none;">DUMMY TEXT</div>
2
3
<button id="expand" name="expand">Show The Div</button>
4
JS:
JavaScript
1
5
1
document.getElementById("expand").addEventListener("click", function()
2
{
3
document.getElementById('unhide').style.display = "block";
4
});
5
How can I make the same button hide the div after clicking it again? Is it possible to alter the code I am using now?
Advertisement
Answer
use toggle to simple hide and unhide div
JavaScript
1
4
1
$("#expand").click(function() {
2
$("#unhide").toggle();
3
});
4