-3

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/

Jonas
  • 121,568
  • 97
  • 310
  • 388
Annie The Cross
  • 173
  • 1
  • 3
  • 9

1 Answers1

1

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")
    })
});

Working Demo

Milind Anantwar
  • 81,290
  • 25
  • 94
  • 125