Currently, I am working on implementing a drop-down menu for a school project. While most of the functionality is in place, I encountered an issue with JQuery events that has me stumped. When I click on a list item, the name is set correctly, but then the events cease to work. I even tried putting the handlers on parent elements, but still no luck.
Below is a snippet of the JQuery code:
$(document).ready(function(){
$('nav ul').on('mouseenter', '.menu1', function(){
$('.menu1 ul').removeClass("hidden");
});
$('nav ul').on('mouseleave', '.menu1', function(){
setTimeout(function(){
$('.menu1 ul').addClass("hidden");
}, 300);
});
$('nav ul').on('click', '.menu1 ul li', function(){
$('.menu1').text($(this).text());
});
});
I have also created a CodePen demo for the list: