0

http://jsfiddle.net/h8rxa3pj/2/

$("#open_link").hover(function() {
    $("#menu").removeClass("hidden");
},function() {
    if ($("#menu").is(":hover")) {
        $("#menu").mouseleave(function() {
            $("#menu").addClass("hidden");
        });
    }
    else {
        $("#menu").addClass("hidden");
    };
});

I have looked at the other questions on this and tried pretty much every solution except the ones I couldn't understand.

How do I check if the mouse is over an element in jQuery?

I feel like Arthur's answer could help but I'm really new to jQuery/JS and I don't know how to apply it here. Help appreciated

Community
  • 1
  • 1
acani
  • 3
  • 3
  • Every time you leave `#open_link` it will register a _new_ mouseleave listener on `#menu`. That's probably not what you intended. – Halcyon Jun 15 '15 at 14:43
  • @Halcyon is that what's making it break? I seriously have no clue. – acani Jun 15 '15 at 14:47
  • "Menu should stay as long as it or the link is hovered." - I just tried your jsfiddle and as far as I can see it does as intended, the menu appears and remains if the mouse hovers over the link or menu? – smoggers Jun 15 '15 at 14:48
  • @smoggers yes it works in Chrome but in the newest versions of FF and IE the menu won't stay visible when you move your mouse over it from the link – acani Jun 15 '15 at 14:50
  • ah yes I see what you mean now, tested in Firefox and yeah it's not working correctly. I've not used much JavaScript/JQuery, so my solution could be improved no doubt, but I've got a simple working solution that works in FF. I'll post it as an answer – smoggers Jun 15 '15 at 15:10
  • This is such a weird way to solve this problem. Wrap the trigger and the menu in an element, do all the hover logic on that wrapper. That way you don't have to deal with the gap/event-ordering. – Evan Davis Jun 15 '15 at 15:22

1 Answers1

1
$("#open_link, #menu").hover(function() {
    $("#menu").removeClass("hidden");
});
$("#open_link, #menu").mouseleave(function() {
    $("#menu").addClass("hidden");
});
smoggers
  • 3,154
  • 6
  • 26
  • 38
  • Wow thanks so much... I've literally spent hours on this. Can confirm working in FF and IE – acani Jun 15 '15 at 15:23