VOOZH about

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

⇱ Bootstrap 5 Toasts getOrCreateInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Toasts getOrCreateInstance() Method

Last Updated : 23 Jul, 2025

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:

👁 Image
Bootstrap 5 Toasts getOrCreateInstance() Method

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

Comment

Explore