Jquery Double clicking on link removing div content
- by ram
I wrote this code to load the content of a DIV ,when some one clicks on a link.
Now,if you click on a link twice,it is removing the content.
Here is the code
$('a').click(function() {
var id = $(this).attr('class');
if(id == 'first')
{
$('.active').removeClass('active');
$('a.first').addClass('active');
}
else if(id == 'second')
{
$('.active').removeClass('active');
$('a.second').addClass('active');
}
$('#first').toggle(id == 'first');
$('#second').toggle(id == 'second');
});?
<a class="first">one</a>
<a class="second">two</a>
<div>
<li id="first">
<h2>pen</h2>
<div>
<div>parker</div>
</div>
</li>
<li id="second" style="display: none;">
<h2>car</h2>
<div>Bugatti</div>
</div>
</li>
</div>?
.active { color: green; }