VOOZH about

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

⇱ Bootstrap 5 Modal getOrCreateInstance() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Bootstrap 5 Modal getOrCreateInstance() Method

Last Updated : 27 Jul, 2025

Bootstrap 5 Modal getOrCreateInstance() method is used to get the modal instance from a DOM element if it exists or to create a new example for the same element if not exist.

Syntax:

const modal = bootstrap.Modal.getOrCreateInstance('#modal-ID');

Return Value: The Modal getOrCreateInstance() method returns the instance of the Bootstrap Modal either existing or new.

Example 1: In this example, we get the instance of the modal using the getOrCreateInstance() method and then invoke its show() method to show the modal.

Output:

Example 2: In this example, we used the getInstance() method of the modal to get its instance and then called its dispose() method so it can destroy an element’s modal and getOrCreateInstance() method of the modal to create and get a new instance.

Output:

Reference: https://getbootstrap.com/docs/5.0/components/modal/#getorcreateinstance

Comment

Explore