I have implemented a JavaScript snippet that enables a collapse feature with color and chevron changes based on its open or closed state. Now, I am attempting to replicate this functionality for a different button but haven't had success by changing the IDs and class names as expected.
$('#accolades').on('shown.bs.collapse', function() {
$(".js-chevron").addClass('fa-chevron-up').removeClass('fa-chevron-down');
$(".js-button").addClass('button-accolades').removeClass('btn-outline-light');
});
$('#accolades').on('hidden.bs.collapse', function() {
$(".js-chevron").addClass('fa-chevron-down').removeClass('fa-chevron-up');
$(".js-button").addClass('btn-outline-light').removeClass('button-accolades');
});
Is there a way to reuse this code for multiple instances so that each instance acts independently of the others?
Thank you in advance!