Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple data-target in Bootstrap? [duplicate]

I'd like to target two divs for expand when clicking on a single trigger? Is that possible?

like image 791
mtndan Avatar asked Dec 02 '13 22:12

mtndan


People also ask

What is the difference between toggle and target in Bootstrap modal?

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!

What is data-target in Bootstrap 2?

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.

How do I Collapse a class in Bootstrap 3?

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.

What is the default size of a bootstrap modal?

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.


4 Answers

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>
like image 150
Bass Jobsen Avatar answered Oct 29 '22 09:10

Bass Jobsen


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>
like image 36
Franck Valentin Avatar answered Oct 29 '22 07:10

Franck Valentin


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.

like image 41
mark.monteiro Avatar answered Oct 29 '22 07:10

mark.monteiro


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).

like image 34
Acia Delilah Avatar answered Oct 29 '22 07:10

Acia Delilah