Enable tabbable list item via JavaScript (each list item needs to be activated individually):
{{< highlight js >}}
-$('#myList a').on('click', function (e) {
- e.preventDefault()
- $(this).tab('show')
+var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
+triggerTabList.forEach(function (triggerEl) {
+ var tabTrigger = new bootstrap.Tab(triggerEl)
+
+ triggerEl.addEventListener('click', function (e) {
+ e.preventDefault()
+ tabTrigger.show()
+ })
})
{{< /highlight >}}
You can activate individual list item in several ways:
{{< highlight js >}}
-$('#myList a[href="#profile"]').tab('show') // Select tab by name
-$('#myList a:first-child').tab('show') // Select first tab
-$('#myList a:last-child').tab('show') // Select last tab
-$('#myList a:nth-child(3)').tab('show') // Select third tab
+var triggerEl = document.querySelector('#myTab a[href="#profile"]')
+bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
+
+var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
+bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
{{< /highlight >}}
### Fade effect
### Methods
-#### $().tab
+#### constructor
Activates a list item element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
</div>
<script>
- $(function () {
- $('#myList a:last-child').tab('show')
- })
+ var firstTabEl = document.querySelector('#myTab a:last-child')
+ var firstTab = new bootstrap.Tab(firstTabEl)
+
+ firstTab.show()
</script>
{{< /highlight >}}
-#### .tab('show')
+#### show
Selects the given list item and shows its associated pane. Any other list item that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (for example, before the `shown.bs.tab` event occurs).
{{< highlight js >}}
-$('#someListItem').tab('show')
+ var someListItemEl = document.querySelector('#someListItem')
+ var tab = new bootstrap.Tab(someListItemEl)
+
+ tab.show()
+{{< /highlight >}}
+
+#### dispose
+
+Destroys an element's tab.
+
+#### getInstance
+
+*Static* method which allows you to get the tab instance associated with a DOM element
+
+{{< highlight js >}}
+var triggerEl = document.querySelector('#trigger')
+var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
{{< /highlight >}}
### Events
</table>
{{< highlight js >}}
-$('a[data-toggle="list"]').on('shown.bs.tab', function (e) {
+var tabEl = document.querySelector('a[data-toggle="list"]')
+tabEl.addEventListener('shown.bs.tab', function (e) {
e.target // newly activated tab
e.relatedTarget // previous active tab
})