I have small blocks with a title and when clicked should drop toogle, how can I apply the code to subsequent blocks if there are several?

  • 0
    $(function () {
     $('.answers_toggle').click(function() {
         
         $('#answers_text').slideToggle( function() {
    
         });
         $(this).toggleClass("active");
     });
    });


    JavaScript Ruby Townsend, May 17, 2020

  • 1 Answers
  • 0
    Depending on the markup. For example, if the block with the text goes right under the heading:

    $(function () {
    $('.answers_toggle').click(function() {
    $(this).toggleClass('active').next('.answers_text').slideToggle();
    });
    });


    Well, change the text ID for the class
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!