I'd like to target two divs for expand when clicking on a single trigger? Is that possible?
The toggle tells Bootstrap what to do and the target tells Bootstrap which element is going to open. So whenever a link like that is clicked, a modal with an id of “basicModal” will appear. Thanks for contributing an answer to Stack Overflow!
2 Answers 2. data-target is used by bootstrap to make your life easier. You (mostly) do not need to write a single line of Javascript to use their pre-made JavaScript components. The data-target attribute should contain a CSS selector that points to the HTML Element that will be changed.
From the Bootstrap 3 documentation: The data-target attribute accepts a CSS selector to apply the collapse to. Therefore you can use a comma-separated list of id's, class selector etc. for the data-target attribute value: You can see an extensive list of valid CSS selectors on the w3schools website.
By default, modals are medium in size. For a complete reference of all modal options, methods and events, go to our Bootstrap JS Modal Reference.
Use the same class for both div's and set your data-target
according this. Give your div's also the same parent (can also be a class) and set data-parent
according this.
<button type="button" data-parent="#wrap" data-toggle="collapse" data-target=".demo">
simple collapsible
</button>
<div id="wrap">
<div class="demo collapse">
test1
</div>
<div class="demo collapse">
test1
</div>
</div>
You can simply add all the ids separated by commas in data-target
:
<button type="button" data-toggle="collapse" data-target="#demo,#demo1,#demo2">
Hide them all
</button>
From the Bootstrap 3 documentation:
The data-target attribute accepts a CSS selector to apply the collapse to.
Therefore you can use a comma-separated list of id's, class selector etc. for the data-target
attribute value:
<button class="btn btn-primary" type="button"
data-toggle="collapse" data-target="#target1,#target2,#target3"
aria-expanded="false" aria-controls="target1,target2,target3">
You can see an extensive list of valid CSS selectors on the w3schools website.
There is a solution in Bootstrap 4:
Bootstrap 4 documentation: Multiple targets
The least you need is:
data-toggle="collapse" data-target=".multi-collapse"
for the toggle
button class="collapse multi-collapse"
for each element you need to
toggle(While multiple ids in data-target
indeed don't work).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With