using on() with hover - jQuery

后端 未结 7 1209
感情败类
感情败类 2021-01-26 05:51

This is what I have:

$(\'#blah\').hover(function(){
    $(\'etc\').show();
}, function(){
    $(\'etc\').hide();
});

This works just fine, now

7条回答
  •  迷失自我
    2021-01-26 06:15

    from Jquery docs. Jquery on

    Deprecated as of jQuery 1.8: The name "hover" used as a shorthand for the string "mouseenter mouseleave". It attaches a single event handler for those two events, and the handler must examine event.type to determine whether the event is mouseenter or mouseleave. Do not confuse the "hover" pseudo-event-name with the .hover() method, which accepts one or two functions.

    $("div.test").on({
      mouseenter: function(){
        $(this).addClass("inside");
      },
      mouseleave: function(){
        $(this).removeClass("inside");
      }
    });
    

提交回复
热议问题