How can I check if the cursor is hovering on an element using JQuery

前端 未结 5 1141
离开以前
离开以前 2021-02-18 17:38

It possible to check if the cursor is hovering on an element.

Something like

 $(\"#divId\").is(\"hover\");

NOTE: I just want to check n

5条回答
  •  一个人的身影
    2021-02-18 18:27

    Updated answer!

    $("#foo").hover(function() {
        $(this).data("hovered", true);
    }, function() {
        $(this).data("hovered", false);
    }); 
    

    Testing if it is hovered...

    if ( $("#foo").data("hovered") ) {
        // it is hovered
    } else {
        // it's not hovered
    }
    

提交回复
热议问题