0
How do I define the same code, with different variables, but to perform the same action.
I tried to rewrite it and still, the Javascript
is in error, in case it would be a dropdown menu, with up to 4 levels, I am still in 2° level it, that when clicking outside the menu, the same closes
If the user clicks off the menu, it will close
window.onclick = function(event) {
if (!event.target.matches('.dropbtn')) {
var dropdowns = document.getElementsByClassName("dropdown-content");
var i;
for (i=0; i < dropdowns.length; i++) {
var openDropdown = dropdowns[i];
if (openDropdown.classList.contains('show')) {
openDropdown.classList.remove('show');
}
}
}
}
When the user clicks on the button, toggle between hide and show content 'Dropdown'
/*Primários*/
function funcaoPrincipais() {
document.getElementById("myDropdown").classList.toggle("show");
}
/*Secundários*/
function funcaoPrincipaisPrincipal() {
document.getElementById("myFirstSubForPrincipal").classList.toggle("show");
}
function funcaoPrincipaisInstitucional() {
document.getElementById("myFirstSubForInstitucional").classList.toggle("show");
}
You can do a jsFiddle?
– Sergio
https://jsfiddle.net/xakkbvn5/
– Murilo Melo