I'm not able to make it work, I have a retractile side menu and a button on a bar in the header. I set my menu to margin-left: -250px;
and wanted it when I pressed the button it would go to margin-left: 0;
, thus making the menu appear again.
Menu CSS:
#menu-lateral {
width: 250px;
height: 100%;
margin-left: -250px;
}
Button HTML:
<div class="btn-header">
<a href="" id="btn-menu">
<img src="img/menu.png">
<img src="img/icone.png">
<p>Home</p></a>
</div>
JavaScript I've done:
var clique = document.getElementById("btn-menu");
var menuLateral = document.getElementById("menu-lateral");
clique.onclick = function(){
document.menuLateral.style.marginLeft = "0";
};
My goal is:
When you click the change button in #menu-lateral
margin-left: -250px;
to margin-left: 0;
and when the menu is open, clicking it again will close it (set margin-left: -250px;
again).