diff options
Diffstat (limited to 'site/content/docs/5.1/components/alerts.md')
| -rw-r--r-- | site/content/docs/5.1/components/alerts.md | 13 |
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() ``` |
