Skip to content

Commit cd21ca0

Browse files
committedAug 1, 2019
remove jquery in tab docs
1 parent eecd75d commit cd21ca0

File tree

1 file changed

+35
-15
lines changed
  • site/content/docs/4.3/components

1 file changed

+35
-15
lines changed
 

‎site/content/docs/4.3/components/navs.md

+35-15
Original file line numberDiff line numberDiff line change
@@ -524,19 +524,25 @@ You can activate a tab or pill navigation without writing any JavaScript by simp
524524
Enable tabbable tabs via JavaScript (each tab needs to be activated individually):
525525

526526
{{< 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+
})
530535
})
531536
{{< /highlight >}}
532537

533538
You can activate individual tabs in several ways:
534539

535540
{{< 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
540546
{{< /highlight >}}
541547

542548
### Fade effect
@@ -558,7 +564,7 @@ To make tabs fade in, add `.fade` to each `.tab-pane`. The first tab pane must a
558564
{{< partial "callout-danger-async-methods.md" >}}
559565
{{< /callout >}}
560566

561-
#### $().tab
567+
#### constructor
562568

563569
Activates a tab element and content container. Tab should have either a `data-target` or an `href` targeting a container node in the DOM.
564570

@@ -586,24 +592,37 @@ Activates a tab element and content container. Tab should have either a `data-ta
586592
</div>
587593

588594
<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 = new bootstrap.Tab(firstTabEl)
597+
598+
firstTab.show()
592599
</script>
593600
{{< /highlight >}}
594601

595-
#### .tab('show')
602+
#### show
596603

597604
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).
598605

599606
{{< highlight js >}}
600-
$('#someTab').tab('show')
607+
var someTabTriggerEl = document.querySelector('#someTabTrigger')
608+
var tab = new bootstrap.Tab(someTabTriggerEl)
609+
610+
tab.show()
601611
{{< /highlight >}}
602612

603-
#### .tab('dispose')
613+
#### dispose
604614

605615
Destroys an element's tab.
606616

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+
607626
### Events
608627

609628
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
643662
</table>
644663

645664
{{< 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) {
647667
e.target // newly activated tab
648668
e.relatedTarget // previous active tab
649669
})

0 commit comments

Comments
 (0)
Please sign in to comment.