user1405690
user1405690

Reputation: 149

Jquery addClass and Remove Class on hover

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.

Upvotes: 7

Views: 29323

Answers (4)

Kaidul
Kaidul

Reputation: 15855

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

Use it.hope it help !

Upvotes: 2

thecodeparadox
thecodeparadox

Reputation: 87073

$('#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

Upvotes: 9

ssj1980
ssj1980

Reputation: 391

Hope this helps.

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

Upvotes: 0

VisioN
VisioN

Reputation: 145368

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/

Upvotes: 20

Related Questions