I'm currently developing an HTML application with a sidebar menu that toggles on click. However, I've encountered an issue where the menu doesn't appear until the second click. The first click seems to have no effect.
Here's the CSS code:
#menubalk{
margin-left: -260px;
}
And here's the corresponding HTML code:
<div id="menubutton">
<img src="design/images/menu.png" id="menu" onclick="toggle()" alt=""/>
</div>
<div id="menubalk">
<h5>Menu</h5>
</div>
Lastly, the JavaScript function for toggling the menu:
function toggle () {
var el = document.getElementById("menubalk");
var kop = document.getElementById("kop");
var pag = document.getElementById("pagina");
if ( el.style.marginLeft=="-260px" ) {
el.style.marginLeft="0px";
kop.style.marginLeft="260px";
pag.style.marginLeft="260px";
} else {
el.style.marginLeft="-260px";
kop.style.marginLeft="0px";
pag.style.marginLeft="0px";
}
}
I suspect that I may need to adjust the margin in the JavaScript as well, but I'm unsure how to implement it.
Any assistance you can provide would be greatly appreciated!