Topic: Using Javascript to toggle (show/hide) modal

snirkleshift free asked 3 years ago


In vanilla Bootstrap i can use this method to initialize a modal: const myModal = new bootstrap.Modal(document.getElementById('myModal'), options) and then do things with it like myModal.show().

MDB 4.x has $('#myModal').modal('show') but this gives me the following error message:

Uncaught TypeError: $(...).modal is not a function

What is the MDB 5 way of doing this?


Grzegorz Bujański staff commented 3 years ago

Do you mean the MDB jQuery version or MDB 5? In MDB 5 you can use this code to initialize a modal: const myModal = new mdb.Modal(document.getElementById('myModal')). Then you can use myModal.show()



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Opened

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB Standard
  • MDB Version: 3.2.0
  • Device: PC
  • Browser: All
  • OS: Windows 10
  • Provided sample code: Yes
  • Provided link: No