You can achieve this using jQuery's hover() and addClass() and removeClass() methods. Here's an example:

HTML:

<div class="myDiv">Hover over me</div>

CSS:

.myDiv {
  background-color: blue;
  color: white;
}

.myDiv.hovered {
  background-color: red;
}

jQuery:

$(document).ready(function() {
  $('.myDiv').hover(
    function() {
      $(this).addClass('hovered');
    },
    function() {
      $(this).removeClass('hovered');
    }
  );
});

In this example, when you hover over the .myDiv element, it will add the class .hovered to it, changing its background color to red. When you hover out, it will remove the .hovered class, reverting the background color back to blue

i want to addclass to a div with hover another class and remove class with hover out with jquery

原文地址: https://www.cveoy.top/t/topic/imU8 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录