Skip to content

Bootstrap bootstrap (JS components) API

Bootstrap 5 component JavaScript API — programmatic control of modal, tooltip, popover, and dropdown.

1 class · 5 methods

Components

5 methods

Programmatic API for Bootstrap's JavaScript components. Each component is a class on the bootstrap namespace (e.g. bootstrap.Modal).

new bootstrap.Modal(element, options?)

Creates a Modal instance for a modal element. Use show/hide/toggle to control it.

Parameters

NameTypeDescription
elementElement | stringModal element or selector.
optionsobjectOptional { backdrop, keyboard, focus }.

Returns

Modal

Example

bootstrap
const myModal = new bootstrap.Modal('#myModal');
myModal.show();
Component.getOrCreateInstance(element, options?)

Static method that returns an existing component instance for the element, or creates a new one.

Returns

Component instance

Example

bootstrap
const m = bootstrap.Modal.getOrCreateInstance('#myModal');
m.hide();
instance.show() / .hide() / .toggle()

Shows, hides, or toggles a component instance. Dispatches the corresponding before/after events.

Returns

void

Example

bootstrap
const tooltip = bootstrap.Tooltip.getOrCreateInstance('#btn');
tooltip.show();
tooltip.hide();
instance.dispose()

Destroys a component instance, removing its DOM artifacts and event listeners.

Returns

void

Example

bootstrap
const popover = bootstrap.Popover.getInstance('#btn');
if (popover) popover.dispose();
instance.update()

Updates the position/content of a component (used by tooltip, popover, dropdown).

Returns

void

Example

bootstrap
const dropdown = new bootstrap.Dropdown('#menuBtn');
dropdown.update();