Here is my jQuery:
$(\'.ask\').click(function() {
$(\'.addtitle\').slideToggle(\'fast\', function() {
// Animation complete.
});
});
<
$('.ask').click(function() {
var $this = $(this);
$this.find('.addtitle').slideToggle('fast', function() {
// Animation complete.
if($this.text() === '-')
$this.text('+');
else
$this.text('-');
});
});
You can do it using .next() and .toggle() like this:
$('.ask').toggle(function() {
$(this).text('-').next('.addtitle').slideDown('fast');
}, function() {
$(this).text('+').next('.addtitle').slideUp('fast');
});
.next(selector) get the next sibling if it matches the selector, if there may be something in-between then use .nextAll('.addtitle:first'), .toggle() cycles between the functions you provide on each click
event, so it'll swap the text and slide appropriately every click.