Pythonista
Pythonista

Reputation: 11615

how to prevent default collapse behavior on div

I want to give a list of items I'm iterating over the ability to collapse and uncollapse again when pressing a hide button.

Pretty easy to do using bootsraps collapse class and setting up the appropriate anchor link / id references.

However, the first time I click the button it will collapse and then unhide the element again. Because I haven't set the initial collapse class (because I want it to show by default). After this everything runs smoothly it's just the first click that doesn't work properly.

How would I go about preventing this default behavior?

I know I could switch out the bootstrap class for a button / jQuery using the collapse class just seems to be a better way to integrate the feature.

Edit: updated bootply for non-working vs working first click

bootply

Upvotes: 0

Views: 124

Answers (1)

reinder
reinder

Reputation: 2551

The element you want to be initially visible still needs the collapse class. To show it by default just add the in class as well. Updated your bootply here with an example

Upvotes: 2

Related Questions