Add/Remove CSS Class to any element using JQuery

Virendradugar
Posted by Virendradugar under jQuery category on | Views : 6599
Below code will apply the CSS class to a tag element using JQuery. You can download the Jquery from http://docs.jquery.com/Downloading_jQuery

 <style type="text/css">
.color
{
color: Red;
font-weight: bold;
}
</style>

<script type="text/javascript" src="Script/jquery-1.3.2.js"></script>

<script type="text/javascript">
$(document).ready(function(){
$("#hypDotnetFunda").addClass("color");
});
</script>


Here is a tag with hypDotnetFunda ID.

<a id="hypDotnetFunda" href="http://www.dotnetfunda.com/default.aspx">DotnetFunda</a>


Same way you can also remove the class using removeClass() method.


<script type="text/javascript">
$(document).ready(function(){
$("#hypDotnetFunda").removeClass("color");
});
</script>


Enjoy..

Comments or Responses

Login to post response