Skip to content
Advertisement

Bootstrap collapse/expand multiple targets with different collapse states

In the bootstrap docs, there is an example of how to toggle single and multiple targets, see https://getbootstrap.com/docs/4.0/components/collapse/?#multiple-targets.

When clicking “Toggle the first element” and then “Toggle both elements”, the state of the two elements are mismatched e.g. one collapsed the other not.

How can I achieve that both/multiple elements are collapsed/shown when clicking “Toggle both elements” no matter what state the element had before.

Advertisement

Answer

So after Dealish Teppes hint, I came up with this solution. Note to remove the data-target and add id on the “toggle both” button.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement