![]() |
VOOZH | about |
Bootstrap 5 Toast getOrCreateInstance() Method is used to get the already existing instance or create a new instance and return that to the caller. The returned instance can be used to call other methods for the toast component. This method accepts a DOM element or the selector for an element as the parameter.
Syntax:
bootstrap.Toast.getOrCreateInstance("#element-id");Return Value: This method returns the Bootstrap 5 Toast instance to the caller.
Example 1: In this example, we used the getOrCreateInstance method to create the toast instance and then called its show method.
Output:
Example 2: In this example, we used the getOrCreateInstance method of the toast component to create the instance of the toast and then toggled it using the show and hide method.
Output:
Reference: https://getbootstrap.com/docs/5.2/components/toasts/#methods