$(document).ready(function () { $(".thisDiv").hover(function () { var className = $(this)[0].className; $(this).removeClass(function (index, className) { return className; }).addClass('thisDiv'); }); });
<html> <head> <title>removeClass</title> </head> <body> <table> <tr> <td> <span class="thisDiv Green"> Hover Me 1 </span></td> <td> <span class="thisDiv Yellow"> Hover Me 2 </span></td> <td> <span class="thisDiv Aqua"> Hover Me 3 </span> </td> </tr> </table><br /> <input type="button" value="Reset" onclick="location.reload()" /> </body> </html>
.thisDiv { background-color:Red; width:200px; height:200px; display:block; } .Green { background-color:Green!important; } .Yellow { background-color:Yellow!important; } .Aqua { background-color:aqua!important; }