How to implement the appearance and disappearance of the unit when pressing the button (in pure JS)?

Good day!
Tell me, please, how to realize the appearance and disappearance of the unit when pressing the button (in pure JS)?

The unit is initially "display:none;"
Connected script
function viewDiv(){ 
document.getElementById("filters").style.display = "block"; 
};

Connected to the button attribute onmousedown="viewDiv()", but it only opens the unit and to close - not close.

Tell me how to add the ability to hide again to display: none?
Many thanks in advance! (just learning JS)
April 3rd 20 at 18:30
1 answer
April 3rd 20 at 18:32
Solution
make the test - if the unit is currently display: none, then change to display: block. And Vice versa - if the unit is currently written display: block, then change to none

if (document.getElementById("filters").style.display == 'block') { 
 document.getElementById("filters").style.display = "none";
}
else {
 document.getElementById("filters").style.display = "block";
}
I'll try it now - Kaci56 commented on April 3rd 20 at 18:35

Find more questions by tags JavaScriptHTML