Can anybody explain to me why when a code works normally, but the second I use addEventListener it won't read the "display none" function after
} else
I know there is a lot of codes and questions out there, where people ask about the onclick function. But I haven't found any on why I have to rewrite the code just because I use addEventListener.
So here it will open the menu but it won't close it again but if I remove the addEventListener it will.
document.getElementById("menu-item-11109").addEventListener("click", myFunction);
function myFunction() {
var x = document.getElementById('closemenu');
if (x.style.display === 'none') {
x.style.display = 'block';
} else {
x.style.display = 'none';
}
}
HTML
<li onclick="myFunction()" id="menu-item-11109">
<a>Opskrifter</a>
<ul id="closemenu">
<li>
<a href="https://kvalitet-extensions.dk/category/mad/">Mad og drikke</a>
</li>
</ul>