I am currently working on collapsible sections that should open and close when clicked, but unfortunately they are not closing once opened.
You can view the use case here: Use case
This is the code I am using:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('.markdown-block .sqs-block-content h3').addClass('ui-closed').css('cursor','pointer');
$('.markdown-block .sqs-block-content h3').css('cursor','pointer');
$(".markdown-block .sqs-block-content h3").nextUntil("h3").slideToggle();
$(".markdown-block .sqs-block-content h3").click(function() {
$(".markdown-block .sqs-block-content h3").nextUntil("h3").slideUp();
$(".markdown-block .sqs-block-content h3").removeClass('ui-open');
$(".markdown-block .sqs-block-content h3").addClass('ui-closed');
$(this).nextUntil("h3").slideDown();
$(this).toggleClass('ui-closed ui-open');
});
});
</script>
Can anyone help me modify this code so that the sections collapse after being opened?