Mohammedmehdi Khatau
Mohammedmehdi Khatau

Reputation: 43

Alternative Jquery mouse event

Alright so the code below works fine if I click outside the #nav div. I was asking if it is possible to just move the mouse away from the #nav div to make it disappear. I don't want to 'click' to hide the div.

$(document).mouseup(function (e)
{
    var container = $("#nav");

    if (container.has(e.target).length === 0)
    {
        container.hide();
    }
});

Any help will be appreciated :)

Upvotes: 0

Views: 219

Answers (1)

Kevin Bowersox
Kevin Bowersox

Reputation: 94429

Assign a function that hides the element on the mouseleave event.

$("#nav").mouseleave(function(){
    $(this).hide(); 
});

Fiddle: http://jsfiddle.net/howderek/SRMT8/

Upvotes: 4

Related Questions