According to the Bootstrap 5 documentation, you can instantiate a collapse using the constructor. For example:
var myCollapse = document.getElementById('myCollapse')
var bsCollapse = new bootstrap.Collapse(myCollapse, {
toggle: false
})
I wanted to close it upon clicking on a specific element, so I implemented the following:
document.body.addEventListener("click", el => {
if (el.target.matches("#send-search")) {
el.preventDefault();
// Close the element
new bootstrap.Collapse(document.querySelector("#find-el"), {
hide: true,
});
// Perform certain operations only when the element is completely closed
}
});
The element now closes as expected...
However, I require that a particular operation be executed only after the element has been fully closed.