Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS Bootstrap 4 Basics (Retired) Using Bootstrap Components Displaying a Modal Window

I'm unsure about the Bootstrap data-toggle and data-target attributes

I can't find good documentation regarding the data-toggle and data-target attributes. From my findings, I'm GUESSING that data-toggle is a class of some sort for a particular element. For example data-toggle="modal" data-target="#myModal" - this will trigger a modal with the ID of "myModal".

However, I found a few more:

data-toggle="modal" data-toggle="collapse" data-toggle="dropdown" data-toggle="tab"

I'm, again, guessing, that theses different values for the attributes are for different types of elements. For example, "collapse" might be used for a navigation menu? Is that correct?

Thanks

1 Answer

Wilson Usman
Wilson Usman
35,206 Points

Kristian,

You might want to go through this page http://getbootstrap.com/javascript/

It helped me understand it a lot better. You're on the right track though.

Take a look at this sample code for better understanding.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"/>

<div class="dropdown">
  <a class="dropdown-toggle" data-toggle="dropdown" href="#">Dropdown trigger</a>
  <ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
    <li><a href="#">Item</a></li>
  </ul>
</div>