aboutsummaryrefslogtreecommitdiff
path: root/site/content/docs/5.1/components/alerts.md
diff options
context:
space:
mode:
authorGeoSot <[email protected]>2021-06-29 19:08:15 +0300
committerXhmikosR <[email protected]>2021-08-23 18:30:42 +0300
commitcd6776b5b1b79986790604014eddd1b575fe5df7 (patch)
tree0a1146f9061b3034ae3b390713689c0d819e590b /site/content/docs/5.1/components/alerts.md
parent480c7c9c433c2ece50ffc6503eb03292e3853f39 (diff)
downloadbootstrap-js-docs-tweaks.tar.xz
bootstrap-js-docs-tweaks.zip
Diffstat (limited to 'site/content/docs/5.1/components/alerts.md')
-rw-r--r--site/content/docs/5.1/components/alerts.md13
1 files changed, 12 insertions, 1 deletions
diff --git a/site/content/docs/5.1/components/alerts.md b/site/content/docs/5.1/components/alerts.md
index 21855dd25..d8a75d64f 100644
--- a/site/content/docs/5.1/components/alerts.md
+++ b/site/content/docs/5.1/components/alerts.md
@@ -211,6 +211,15 @@ See the [triggers](#triggers) section for more details.
### Methods
+You can create an alert instance with the alert constructor, for example:
+
+```js
+var myAlert = document.getElementById('myAlert')
+var bsAlert = new bootstrap.Alert(myAlert)
+```
+
+This makes an alert listen for click events on descendant elements which have the `data-bs-dismiss="alert"` attribute. (Not necessary when using the data-api’s auto-initialization.)
+
{{< bs-table >}}
| Method | Description |
| --- | --- |
@@ -220,9 +229,11 @@ See the [triggers](#triggers) section for more details.
| `getOrCreateInstance` | Static method which returns an alert instance associated to a DOM element or create a new one in case it wasn't initialised. You can use it like this: <code>bootstrap.Alert.getOrCreateInstance(element)</code>. |
{{< /bs-table >}}
+Basic usage:
+
```js
var alertNode = document.querySelector('.alert')
-var alert = bootstrap.Alert.getInstance(alertNode)
+var alert = bootstrap.Alert.getOrCreateInstance(alertNode)
alert.close()
```