Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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?


1 Answer

Wilson Usman
Wilson Usman
35,206 Points


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>