One way to initialize all tooltips on a page would be to select them by their `data-toggle` attribute:
{{< highlight js >}}
-$(function () {
- $('[data-toggle="tooltip"]').tooltip()
+var tooltipTriggerList = [].slice.call(document.querySelectorAll('[data-toggle="tooltip"]'))
+var tooltipList = tooltipTriggerList.map(function (tooltipTriggerEl) {
+ return new bootstrap.Tooltip(tooltipTriggerEl)
})
{{< /highlight >}}
Trigger the tooltip via JavaScript:
{{< highlight js >}}
-$('#example').tooltip(options)
+var exampleEl = document.getElementById('example')
+var tooltip = new bootstrap.Tooltip(exampleEl, options)
{{< /highlight >}}
{{< callout warning >}}
Tooltip position attempts to automatically change when a parent container has `overflow: auto` or `overflow: scroll` like our `.table-responsive`, but still keeps the original placement's positioning. To resolve, set the `boundary` option to anything other than default value, `'scrollParent'`, such as `'window'`:
{{< highlight js >}}
-$('#example').tooltip({ boundary: 'window' })
+var exampleEl = document.getElementById('example')
+var tooltip = new bootstrap.Tooltip(exampleEl, {
+ boundary: 'window'
+})
{{< /highlight >}}
{{< /callout >}}
{{< partial "callout-danger-async-methods.md" >}}
{{< /callout >}}
-#### `$().tooltip(options)`
-
-Attaches a tooltip handler to an element collection.
-
-#### `.tooltip('show')`
+#### show
Reveals an element's tooltip. **Returns to the caller before the tooltip has actually been shown** (i.e. before the `shown.bs.tooltip` event occurs). This is considered a "manual" triggering of the tooltip. Tooltips with zero-length titles are never displayed.
-{{< highlight js >}}$('#element').tooltip('show'){{< /highlight >}}
+{{< highlight js >}}tooltip.show(){{< /highlight >}}
-#### `.tooltip('hide')`
+#### hide
Hides an element's tooltip. **Returns to the caller before the tooltip has actually been hidden** (i.e. before the `hidden.bs.tooltip` event occurs). This is considered a "manual" triggering of the tooltip.
-{{< highlight js >}}$('#element').tooltip('hide'){{< /highlight >}}
+{{< highlight js >}}tooltip.hide(){{< /highlight >}}
-#### `.tooltip('toggle')`
+#### toggle
Toggles an element's tooltip. **Returns to the caller before the tooltip has actually been shown or hidden** (i.e. before the `shown.bs.tooltip` or `hidden.bs.tooltip` event occurs). This is considered a "manual" triggering of the tooltip.
-{{< highlight js >}}$('#element').tooltip('toggle'){{< /highlight >}}
+{{< highlight js >}}tooltip.toggle(){{< /highlight >}}
-#### `.tooltip('dispose')`
+#### dispose
Hides and destroys an element's tooltip. Tooltips that use delegation (which are created using [the `selector` option](#options)) cannot be individually destroyed on descendant trigger elements.
-{{< highlight js >}}$('#element').tooltip('dispose'){{< /highlight >}}
+{{< highlight js >}}tooltip.dispose(){{< /highlight >}}
-#### `.tooltip('enable')`
+#### enable
Gives an element's tooltip the ability to be shown. **Tooltips are enabled by default.**
-{{< highlight js >}}$('#element').tooltip('enable'){{< /highlight >}}
+{{< highlight js >}}tooltip.enable(){{< /highlight >}}
-#### `.tooltip('disable')`
+#### disable
Removes the ability for an element's tooltip to be shown. The tooltip will only be able to be shown if it is re-enabled.
-{{< highlight js >}}$('#element').tooltip('disable'){{< /highlight >}}
+{{< highlight js >}}tooltip.disable(){{< /highlight >}}
-#### `.tooltip('toggleEnabled')`
+#### toggleEnabled
Toggles the ability for an element's tooltip to be shown or hidden.
-{{< highlight js >}}$('#element').tooltip('toggleEnabled'){{< /highlight >}}
+{{< highlight js >}}tooltip.toggleEnabled(){{< /highlight >}}
-#### `.tooltip('update')`
+#### update
Updates the position of an element's tooltip.
-{{< highlight js >}}$('#element').tooltip('update'){{< /highlight >}}
+{{< highlight js >}}tooltip.update(){{< /highlight >}}
### Events
</table>
{{< highlight js >}}
-$('#myTooltip').on('hidden.bs.tooltip', function () {
+var myTooltipEl = document.getElementById('myTooltip')
+var tooltip = new bootstrap.Tooltip(myTooltipEl)
+
+myTooltipEl.addEventListener('hidden.bs.tooltip', function () {
// do something...
})
+
+tooltip.hide()
{{< /highlight >}}