I'm setting up a few jquery slideToggle for a filter system I have and I'm trying to have them use the same classes. There will be about 5 of the same slide toggle on the page but when I close / open one of them, it closes them all and I'm wondering how I can adjust the the javascript so each one closes individually.
<div class="tc-facet-header tc-toggle-show">
<h3>Header One</h3>
<span><i class="bi bi-chevron-down"></i><i class="bi bi-chevron-up"></i></span>
</div>
<div class="tc-facet tc-facet-open">
Fitler Content 1
</div>
<div class="tc-facet-header tc-toggle-show">
<h3>Header two</h3>
<span><i class="bi bi-chevron-down"></i><i class="bi bi-chevron-up"></i></span>
</div>
<div class="tc-facet tc-facet-open">
Fitler Content 2
</div>
The JS I use is
<script>
$(document).ready(function(){
var $content = $(".tc-facet").show();
$(".tc-facet-header").on("click", function(e){
$(this).toggleClass("tc-toggle-show");
$(this).toggleClass("tc-toggle-hide");
$content.slideToggle();
});
});
When I click on a h3 header of either one it will open / close both the .tc-facet divs instead of just the one i click on.
Your current jquery code is targeting all
.tc-facetthat's why. You need to target each individual.tc-facet. Try this code