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 class cfse_a.
-
api.jquery.com/hover, api.jquery.com/addClass and api.jquery.com/removeClass.Guffa– Guffa2012-05-22 17:06:21 +00:00Commented May 22, 2012 at 17:06
Add a comment
|
4 Answers
Use hover event with addClass and removeClass methods:
$("#searchput").hover(function() {
$(this).addClass("cfse_a");
}, function() {
$(this).removeClass("cfse_a");
});
1 Comment
VisioN
@AndersEriksson If it works like a charm, you should upvote the answer and not downvote it.
$('#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()