33

I am trying to use some of the jQuery plugins for the Bootstrap framework and they use an attribute named "data-toggle". I am getting the warning "attribute data toggle is not a valid atribute of a".

Where does data-toggle come form?

BryanH
  • 5,826
  • 3
  • 34
  • 47
James
  • 2,951
  • 8
  • 41
  • 55
  • [Follow this link for bootstrap documentation regarding "data-toggle" and so on.](http://getbootstrap.com/2.3.2/javascript.html#overview) Hope this helps although it is coming at a late hour – user28864 Dec 01 '13 at 23:01

4 Answers4

81

In HTML5, any attribute that starts with data- is a valid custom attribute. Basically, it's a way to attach custom data to elements that aren't explicitly defined in the HTML specification.

In earlier versions of HTML, this does not validate, however. Don't worry about that too much though. Browsers generally just ignore attributes they don't know about. This doesn't stop libraries like jQuery from reading them.

mac
  • 42,153
  • 26
  • 121
  • 131
Richard Neil Ilagan
  • 14,627
  • 5
  • 48
  • 66
21

If you look in the JavaScript Collapse plugin documentation of Bootstrap you will find a reasonably clear example of the workings of the collapse API and the relationship and uses of the pair data-toggle (which triggers the functionality) and data-target (which sets the behavior), plus other interesting tidbits.

vegemite4me
  • 6,621
  • 5
  • 53
  • 79
cucu8
  • 891
  • 10
  • 12
19

It is a Bootstrap defined HTML5 data attribute.

Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
4

To quickly add dropdown functionality to any element just add data-toggle="dropdown" defined HTML5 data attribute, and any valid bootstrap dropdown will automatically be activated.

Junaid
  • 2,572
  • 6
  • 41
  • 77