VOOZH about

URL: https://www.geeksforgeeks.org/bootstrap/bootstrap-5-toasts-getinstance-method/

⇱ Bootstrap 5 Toasts getInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Toasts getInstance() Method

Last Updated : 22 Jul, 2024

Bootstrap 5 Toast getInstance() method is used to get the already existing instance of the bootstrap Toast and return it to the caller. This method does not create a new instance if it does not exists. The caller can use the instance of the toast to perform other tasks or to call other methods of the toast component.

Syntax:

bootstrap.Toast.getInstance("#element-id");

Parameters: This method accepts an HTML element or the selector of an element as its parameter

Return Value: This method returns the Bootstrap 5 Toast instance to the caller.

Example 1: In this example, we used the getInstance() method of the toast to get the toast instance and then it calls show() method to make it visible.

Output:

Example 2: In this example, we used the getInstance() method of the toast to get the toast instance and then call its dispose() method to remove the toast, so that it will not show anymore.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/toasts/#getinstance

Comment

Explore