The task is to create such an underscore when hovering over a navigation item:
I decided to create the following element for this:
.underline { position: absolute; margin-top: 4px; height: 1px; width: 20px; background-color: red;/*color for test z-index: 1000; } <div class='underline'> </div> and used the following jQuery code:
$(document).ready(function(){ $(".main-nav_item").hover(function() { $(this).append($('.underline')); }); // или же $(".main-nav_item").mouseenter(function() { $(this).append($('.underline')); }); $(".main-nav_item").mouseleave(function() { $(this).siblings('.underline').removeClass(); }); }); Considering that the elements in the picture above have the class .main-nav_item everything should have worked correctly, but I ran into the following problem: when you move the cursor from a link not to another link, but to some other element, the underscore effect is still remains. If you lead to another link - everything works correctly.
As you can see, applied 2 options jQuery, but not one did not fit. Please tell me what could be the problem. Thank you.
