What is the `data-target` attribute in Bootstrap 3?

Twitter Bootstrap-3

Twitter Bootstrap-3 Problem Overview


Can you tell me what is the system or behavior behind the data-target attribute used by Bootstrap 3?

I know that data-toggle used to aim API JavaScript of Bootstrap of graphical functionality.

Twitter Bootstrap-3 Solutions


Solution 1 - Twitter Bootstrap-3

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.

Modal Example Code from BS3:

<!-- Button trigger modal -->
<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  [...]
</div>

In this example, the button has data-target="#myModal", if you click on it, <div id="myModal">...</div> will be modified (in this case faded in). This happens because #myModal in CSS selectors points to elements that have an id attribute with the myModal value.

Further information about the HTML5 "data-" attribute: https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Using_data_attributes

Solution 2 - Twitter Bootstrap-3

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestiondarkomenView Question on Stackoverflow
Solution 1 - Twitter Bootstrap-3PascalmhView Answer on Stackoverflow
Solution 2 - Twitter Bootstrap-3user3098847View Answer on Stackoverflow