how can I use 'next' in this case? Doesn't work...
var that = $( ".class" ).next( "p" );
if (that.hasClass('active')) {
that.slideUp('slow', function () {
that.removeClass('active');
});
}
This should show the case: https://jsfiddle.net/4Lmuydak/
You need to attach click event to h3
elements and then toggle the visibility of next sibling p element:
$('h3').click(function(){
$(this).next('p').slideToggle('slow',function(){
$(this).toggleClass("active")
})
});