Apolo Radomer Apolo Radomer - 1 year ago 77
CSS Question

Hide and Unhide div with the same button

I am using a code that unhides a hidden div.


<div id="unhide" style="display:none;">DUMMY TEXT</div>

<button id="expand" name="expand">Show The Div</button>


document.getElementById("expand").addEventListener("click", function()
document.getElementById('unhide').style.display = "block";

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?

Answer Source

use toggle to simple hide and unhide div

$("#expand").click(function() {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download