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?
-
$(function () { $('.answers_toggle').click(function() { $('#answers_text').slideToggle( function() { }); $(this).toggleClass("active"); }); });
JavaScript Ruby Townsend, May 17, 2020 -
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 classAnonymous
1 Answers
Your Answer
To place the code, please use CodePen or similar tool. Thanks you!