简体   繁体   中英

Jquery addClass and Remove Class on hover

好的,当鼠标悬停在元素#searchput时,我想向元素#searchput添加类cfse_a ,然后当鼠标悬停在元素上时,将类cfse_a删除。

Use hover event with addClass and removeClass methods:

$("#searchput").hover(function() {
    $(this).addClass("cfse_a");
}, function() {
    $(this).removeClass("cfse_a");
});

DEMO: http://jsfiddle.net/G23EA/

$('#searchput').hover(function() {
  $(this).addClass('cfse_a'); // add class when mouseover happen
}, function() {
  $(this).removeClass('cfse_a'); // remove class when mouseout happen
});

You can also use:

$('#searchput').hover(function() {
  $(this).toggleClass('cfse_a');
});

see toggleClass()

DEMO

  $("#searchput").hover(function() {
     $(this).addClass("cfse_a");
     }, function() {
   $(this).removeClass("cfse_a");
   });

Use it.hope it help !

Hope this helps.

$('#searchput').mouseover(function() {
    $(this).addClass('cfse_a');
}).mouseout(function(){
    $(this).removeClass('cfse_a');
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM