Components
5 methodsProgrammatic 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
| Name | Type | Description |
|---|---|---|
| element | Element | string | Modal element or selector. |
| options | object | Optional { 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();