I'm using a side menu on a website and wanted it retracted with a click of the button ... it just happens after two clicks !!
function resp() {
var clique = document.getElementById("btn-menu");
var menuLateral = document.getElementById("menu-lateral");
clique.onclick = function (e) {
e.preventDefault();
menuLateral.classList.toggle('toggleMenu');
};
}
I am using a link to call the script function: <a href="#" onClick="resp()" id="btn-menu">
side-menu is the div id of the side menu
toggleMenu is the class that is added to the side menu div
This code I took as the base of someone else, however it was not used as a function () and did not have an onClick in the tag ... however so mine does not work ... does anyone know what it can be ?? it is annoying to have to double-click the menu to retract (this only happens on the first touch after refreshing the page)