From dc5e3328c12058de7fb6404edbe5dcee61f3400f Mon Sep 17 00:00:00 2001 From: Rohit Sharma Date: Mon, 22 Feb 2021 12:31:04 +0530 Subject: Allow constructors to accept a CSS selector (#32245) Co-authored-by: XhmikosR Co-authored-by: Mark Otto --- site/content/docs/5.0/getting-started/javascript.md | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'site/content/docs/5.0/getting-started/javascript.md') diff --git a/site/content/docs/5.0/getting-started/javascript.md b/site/content/docs/5.0/getting-started/javascript.md index 53845fdfc..f57a3aedf 100644 --- a/site/content/docs/5.0/getting-started/javascript.md +++ b/site/content/docs/5.0/getting-started/javascript.md @@ -93,6 +93,15 @@ var modal = new bootstrap.Modal(myModalEl, { keyboard: false }) // initialized w If you'd like to get a particular plugin instance, each plugin exposes a `getInstance` method. In order to retrieve it directly from an element, do this: `bootstrap.Popover.getInstance(myPopoverEl)`. +### CSS selectors in constructors + +You can also use a CSS selector as the first argument instead of a DOM element to initialize the plugin. Currently the element for the plugin is found by the `querySelector` method since our plugins support a single element only. + +```js +var modal = new bootstrap.Modal('#myModal') +var dropdown = new bootstrap.Dropdown('[data-bs-toggle="dropdown"]') +``` + ### Asynchronous functions and transitions All programmatic API methods are **asynchronous** and return to the caller once the transition is started but **before it ends**. -- cgit v1.2.3