diff options
author | Rohit Sharma <rohit2sharma95@gmail.com> | 2021-02-22 10:01:04 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-22 10:01:04 +0300 |
commit | dc5e3328c12058de7fb6404edbe5dcee61f3400f (patch) | |
tree | ef141013ee4df32fbd3e581d9647e71f713bb043 /site/content | |
parent | d983744d12be0937bb1aaef06057385d9b553e0c (diff) |
Allow constructors to accept a CSS selector (#32245)
Co-authored-by: XhmikosR <xhmikosr@gmail.com>
Co-authored-by: Mark Otto <otto@github.com>
Diffstat (limited to 'site/content')
-rw-r--r-- | site/content/docs/5.0/getting-started/javascript.md | 9 | ||||
-rw-r--r-- | site/content/docs/5.0/migration.md | 11 |
2 files changed, 20 insertions, 0 deletions
diff --git a/site/content/docs/5.0/getting-started/javascript.md b/site/content/docs/5.0/getting-started/javascript.md index 53845fdfc2..f57a3aedf6 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**. diff --git a/site/content/docs/5.0/migration.md b/site/content/docs/5.0/migration.md index 94f2214d70..903b282cf6 100644 --- a/site/content/docs/5.0/migration.md +++ b/site/content/docs/5.0/migration.md @@ -9,6 +9,17 @@ toc: true ## v5.0.0-beta3 +### JavaScript + +- All plugins can now accept a CSS selector as the first argument. You can either pass a DOM element or any valid CSS selector to create a new instance of the plugin: + + ```js + var modal = new bootstrap.Modal('#myModal') + var dropdown = new bootstrap.Dropdown('[data-bs-toggle="dropdown"]') + ``` + +## v5.0.0-beta2 + ### Utilities - Dropped the `0` entry in `$border-widths` map to remove the duplicated `.border-0` class. |