jQuery Add and Remove Class Tutorial
home » code » jquery plugins » jquery add and remove class
3/20/2013
View Demo
jQuery
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript">
$("a").click(function() {
$("a").parent().removeClass("selected");
$(this).parent().addClass("selected");
});
</script>
CSS
li.selected a {
color:red;
font-weight:900;
}
HTML
<ul>
<li><a href="#">HOME</a></li>
<li><a href="#">PROFILE></a></li>
<li><a href="#">CONTACT</a></li>
<li><a href="#">ABOAT</a></li>
</ul>