Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jQuery .on() delegated mouseenter and mouseleave [duplicate]

Tags:

jquery

What's the best way to delegate multiple events using .on()?

This is the syntax for one delegated event:

$(document).on('mouseeenter','.foo', function(){});

And here is the syntax for multiple events (not delegated):

$('.foo').on({
    mouseenter: function(){
        //stuff
    },
    mouseleave: function(){
        //stuff
    }
});

I was wondering if there was a more succinct way to do this other then:

$(document).on('mouseenter', '.foo', function(){})
           .on('mouseleave', '.foo', function(){});

It's not a big deal if I have to do it that way, I'm more curious about it than anything.

like image 414
Bella Avatar asked Mar 08 '13 14:03

Bella


People also ask

What is the difference between Mouseout and Mouseleave?

This means that mouseleave is fired when the pointer has exited the element and all of its descendants, whereas mouseout is fired when the pointer leaves the element or leaves one of the element's descendants (even if the pointer is still within the element).

What is Mouseleave in jQuery?

The mouseleave event occurs when the mouse pointer leaves the selected element. The mouseleave() method triggers the mouseleave event, or attaches a function to run when a mouseleave event occurs. Note: Unlike the mouseout event, the mouseleave event only triggers when the mouse pointer leaves the selected elements.

What does Mouseenter function do?

Definition and Usage The mouseenter event occurs when the mouse pointer is over (enters) the selected element. The mouseenter() method triggers the mouseenter event, or attaches a function to run when a mouseenter event occurs..

How do you use Mouseenter?

jQuery mouseenter() This function is executed, when the mouse pointer enters the HTML element. When you enter your mouse cursor over the selected element, it triggers the mouseenter event and once the mouseenter event is occurred, it executes the mouseenter() method to attach the event handler function to run.


1 Answers

$(document).on({
    mouseenter: function(){
        //stuff
    },
    mouseleave: function(){
        //stuff
    }
}, '.foo');
like image 146
undefined Avatar answered Oct 12 '22 05:10

undefined