You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: site/content/docs/4.3/components/navs.md
+35-15
Original file line number
Diff line number
Diff line change
@@ -524,19 +524,25 @@ You can activate a tab or pill navigation without writing any JavaScript by simp
524
524
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
525
525
526
526
{{< highlight js >}}
527
-
$('#myTab a').on('click', function (e) {
528
-
e.preventDefault()
529
-
$(this).tab('show')
527
+
var triggerTabList = [].slice.call(document.querySelectorAll('#myTab a'))
528
+
triggerTabList.forEach(function (triggerEl) {
529
+
var tabTrigger = new bootstrap.Tab(triggerEl)
530
+
531
+
triggerEl.addEventListener('click', function (e) {
532
+
e.preventDefault()
533
+
tabTrigger.show()
534
+
})
530
535
})
531
536
{{< /highlight >}}
532
537
533
538
You can activate individual tabs in several ways:
534
539
535
540
{{< highlight js >}}
536
-
$('#myTab a[href="#profile"]').tab('show') // Select tab by name
537
-
$('#myTab li:first-child a').tab('show') // Select first tab
538
-
$('#myTab li:last-child a').tab('show') // Select last tab
539
-
$('#myTab li:nth-child(3) a').tab('show') // Select third tab
541
+
var triggerEl = document.querySelector('#myTab a[href="#profile"]')
542
+
bootstrap.Tab.getInstance(triggerEl).show() // Select tab by name
543
+
544
+
var triggerFirstTabEl = document.querySelector('#myTab li:first-child a')
545
+
bootstrap.Tab.getInstance(triggerFirstTabEl).show() // Select first tab
540
546
{{< /highlight >}}
541
547
542
548
### Fade effect
@@ -558,7 +564,7 @@ To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must a
558
564
{{< partial "callout-danger-async-methods.md" >}}
559
565
{{< /callout >}}
560
566
561
-
#### $().tab
567
+
#### constructor
562
568
563
569
Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
564
570
@@ -586,24 +592,37 @@ Activates a tab element and content container. Tab should have either a `data-ta
586
592
</div>
587
593
588
594
<script>
589
-
$(function () {
590
-
$('#myTab li:last-child a').tab('show')
591
-
})
595
+
var firstTabEl =document.querySelector('#myTab li:last-child a')
596
+
var firstTab =newbootstrap.Tab(firstTabEl)
597
+
598
+
firstTab.show()
592
599
</script>
593
600
{{< /highlight >}}
594
601
595
-
#### .tab('show')
602
+
#### show
596
603
597
604
Selects the given tab and shows its associated pane. Any other tab that was previously selected becomes unselected and its associated pane is hidden. **Returns to the caller before the tab pane has actually been shown** (i.e. before the `shown.bs.tab` event occurs).
598
605
599
606
{{< highlight js >}}
600
-
$('#someTab').tab('show')
607
+
var someTabTriggerEl = document.querySelector('#someTabTrigger')
608
+
var tab = new bootstrap.Tab(someTabTriggerEl)
609
+
610
+
tab.show()
601
611
{{< /highlight >}}
602
612
603
-
#### .tab('dispose')
613
+
#### dispose
604
614
605
615
Destroys an element's tab.
606
616
617
+
#### getInstance
618
+
619
+
*Static* method which allows you to get the tab instance associated with a DOM element
620
+
621
+
{{< highlight js >}}
622
+
var triggerEl = document.querySelector('#trigger')
623
+
var tab = bootstrap.Tab.getInstance(triggerEl) // Returns a Bootstrap tab instance
624
+
{{< /highlight >}}
625
+
607
626
### Events
608
627
609
628
When showing a new tab, the events fire in the following order:
@@ -643,7 +662,8 @@ If no tab was already active, then the `hide.bs.tab` and `hidden.bs.tab` events
643
662
</table>
644
663
645
664
{{< highlight js >}}
646
-
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
665
+
var tabEl = document.querySelector('a[data-toggle="tab"]')
666
+
tabEl.addEventListener('shown.bs.tab', function (e) {
0 commit comments