Jquery addClass and Remove Class on hover
27,660
Solution 1
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/
Solution 2
$('#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()
Solution 3
$("#searchput").hover(function() {
$(this).addClass("cfse_a");
}, function() {
$(this).removeClass("cfse_a");
});
Use it.hope it help !
Author by
user1405690
Updated on July 19, 2022Comments
-
user1405690 almost 2 years
Okay i would like to add a class
cfse_a
to an element#searchput
when the mouse is hovering over the element and then when the mouse is not hovering over the element then remove classcfse_a
.