I am trying to figure out, how to prevent element collapsing and opening again if it is already open. There are multiple collapse elements and I want one to be always open. When collapsed element is clicked, one that is showing collapses and other opens up.
Here is my script to handle the collapse:
$('.li').click(function() {
var current = $(this).find('collapse');
if(!(current).hasClass('show')) {
$('.collapse').removeClass('show');
current.addClass(show);
};
});
It works fine when clicking collapsed element, but when the clicked element is showing, it collapses and shows up again. How to prevent this? I assume I am not very far from the solution, but I cannot figure it out.
EDIT:
here is a fiddle for the case:
https://jsfiddle.net/gc7ejfps/1/
I got edited the script a bit for the case, but now it works as it should. Now my question is, how to add transition to this? I tried with an example from bootstrap collapse (Customizing the collapse transition in bootstrap 4), but didn't get it to work.