Get the first element that the mouse depended on after the MouseLeave event

Guys using jquery / javascript How can I check which one was the first element that the mouse hung after the MouseLeave event?

Basically, I want to check from an array of elements if the mouse rolls these elements or not.

I am trying to use event.relatedTarget. Any help?

+3
source share
4 answers

You can just do

$('element').mouseleave(function(event){
    // assuming that allowedList holds the array of allowed elements
    if ( allowedList.indexOf( event.relatedTarget ) > -1 ){
        // found
    } else {
        // not found
    }
});

demo at http://jsfiddle.net/gaby/V4pJb/

+2
source

Using jQuery, you can do this:

โ€‹$("#foo").mouseโ€‹โ€‹โ€‹leave(function(e) {
    var element = $(e.target);
})โ€‹;โ€‹

. "Hello" mouseout, , . http://jsfiddle.net/k7Gfv/

( ) , . mouseenter ( hover) , . mouseleave ( , reset , ).

0

Not sure what you are looking for, but maybe it could be like this:

var elements = $("#a1, #a2");

$("#a3").on('mouseleave', nextElm);

function nextElm() {
    $('div').on('mouseenter', thisIsIt);
    $("#r").html('Now hover another element ?');   
}

function thisIsIt(e) {
    if ($.inArray(e.target, elements)!=-1){
        $("#r").html('yes');
    }else{
        $("#r").html('no');            
    }
    $("#a3").off('mouseleave', nextElm);
    $('div').off('mouseenter', thisIsIt);
}

Fiddle

0
source

You can do something like this. Here is the violin

var hovered = false;;
$('div').mouseleave(function(e) {
    hovered = true;
});
$('div').hover(function(ev) {
        if (hovered) {
            alert(ev.target);
            hovered = false;
        }
});
โ€‹
0
source

All Articles