Jquery Double clicking on link removing div content
Posted
by
ram
on Stack Overflow
See other posts from Stack Overflow
or by ram
Published on 2012-11-14T16:58:38Z
Indexed on
2012/11/14
16:59 UTC
Read the original article
Hit count: 189
jQuery
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; }?
© Stack Overflow or respective owner