Toggle classes using JQuery

Rajnilari2015
Posted by Rajnilari2015 under jQuery category on | Points: 40 | Views : 1377
Let say we have two hyper links Home and Search.The Home is initially having Active as class . When the Search is clicked , the Active class of Home will be removed and set to Search and vice versa. The below code will do that

<html>
<head>
<script type='text/javascript' src='http://code.jquery.com/jquery-1.4.4.min.js'></script>
<script type="text/javascript">

$(document).ready(function () {

$("ul#tabs li").click(function (e) {
$('ul#tabs li').toggleClass('active');
});
});
</script>
<body>

<div id="divMenuTab">
<ul id="tabs">
<li class="active"><a href="javascript:alert('test1')" id="aTabDocuments" > <span></span>Home</a></li>
<li><a href="javascript:alert('test2');" id="aTabSearch"><span></span>Search</a></li>

</ul>
</div>
</body>
</html>

Comments or Responses

Login to post response