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

前端 未结 5 1029
离开以前
离开以前 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:24

    You can use .hover(). It's can be used like so:

    $("selector").hover(
        function (){
            //mouse over
        },
        function (){
           //mouse out
        }
    );
    

    An example of it's use from the documentation is here:

    $("li").hover(
      function () {
        $(this).append($(" ***"));
      }, 
      function () {
        $(this).find("span:last").remove();
      }
    );
    

提交回复
热议问题