Disable :hover on click

后端 未结 5 1342
醉梦人生
醉梦人生 2021-01-31 20:18

I have a div that has hover:

.div {
  // css
}
.div:hover {
  // css
}

But I want to disable the hover when you click on the

5条回答
  •  花落未央
    2021-01-31 20:24

    Try this:

    JQUERY

    $(function() {                       //run when the DOM is ready
      $(".div").click(function() {  //use a class, since your ID gets mangled
        $(this).addClass("active");      //add the class to the clicked element
      });
    });
    

    CSS

    .div.active:hover {
    cursor:default;
    //same CSS as the DIV
    
    }
    

提交回复
热议问题