JQuery addClass and remove class when freezing

Ok, I would like to add the cfse_a class to the cfse_a element when the mouse is overhanging the element, and then when the mouse is not hovering over the element, then remove the cfse_a class.

+7
source share
4 answers

Use the hover event addClass and removeClass :

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

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

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

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

Use it.hope, it will help!

+2
source

Hope this helps.

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

All Articles