replacement for hover() in jquery1.9?

2019-09-21 02:08发布

问题:

How do I use mouseneter mouseleave instead of hover(). Should i use them both instead of hover()?

$('#somegrid').hover(
function () {
    //something;
},

What about legacy code - I mean what goes in mouseenter , what goes in mouseleave? i just had one action on hover()

回答1:

Like this -

$('#somegrid').on('mouseenter',function(){
 // mouseenter
}).on('mouseleave',function(){
 //  mouseleave
});


回答2:

look at the api for hover

the hover function is shorhand for:

$( selector ).mouseenter( handlerIn ).mouseleave( handlerOut );

or if you are only passing in one handler:

$( selector ).on( "mouseenter mouseleave", handlerInOut );

the examples in the api illustrate this well.