Reputation: 1663
What should I add to the jquery below to get the "show" link to disapear once the toggle is open AND to add a "close" link at the end of the "blablabla" in order to be able to close the toggle)(keeping the slow effect)
jQuery:
var $j = jQuery.noConflict();
$j(function(){
$j('#containertoggle').on('click', 'a.opener', function(){
$j(this).next().toggle('slow')
});
});
HTML :
<ul id="containertoggle">
<li>
<a class="opener">show</a>
<div style="display: none;">
<p>blablablabla</p>
</div>
</li>
<li>
<a class="opener">show</a>
<div style="display: none;">
<p>blablablabla</p>
</div>
</li>
</ul>
Upvotes: 2
Views: 290
Reputation: 55750
You can try this approach.
Also it is a better idea to avoid adding styles to the style attribute
. Use classes instead.
var $j = jQuery.noConflict();
$j(function () {
$j('#containertoggle').on('click', 'a.opener', function () {
var $this = $j(this);
$this.next('div').show('slow');
$this.nextAll('a.closer').first().removeClass('hide');
$this.addClass('hide');
});
$j('#containertoggle').on('click', 'a.closer', function () {
var $this = $j(this);
$this.prev('div').hide('slow');
$this.prevAll('a.opener').first().removeClass('hide');
$this.addClass('hide');
});
});
Upvotes: 1
Reputation: 207901
Try this:
var $j = jQuery.noConflict();
$j('#containertoggle').on('click', 'a.opener', function () {
$j(this).next().toggle('slow').find('p').append('<span> close</span>');
$j(this).hide();
});
$j('#containertoggle').on('click', 'span', function () {
$j(this).closest('div').toggle('slow').closest('li').find('a').show();
$j(this).remove();
});
Upvotes: 1