Topic: Error: "mdb.Alert is not a constructor"

DashMarketingGroup priority asked 3 months ago


I have constructed an alert using the following HTML code:

    <div class="alert fade" id="errAccount" role="alert" data-mdb-color="primary" data-mdb-position="top-right" data-mdb-stacking="true" data-mdb-width="535px" data-mdb-append-to-body="true"
        data-mdb-hidden="true" data-mdb-autohide="true" data-mdb-delay="2000">
        Unable to load application record.
    </div>

and then I am calling it from Javascript using this code:

                    const alertEl = document.getElementById('errAccount');
                    const alert = new mdb.Alert(alertEl);
                    alert.show();

But for some reason, the alert doesn't display and I get the following error in the console:

Uncaught TypeError: mdb.Alert is not a constructor

It makes no sense, because I am including script references to mdb and plugins, so I don't know why this error is happening. Thank you.


Grzegorz Bujański staff answered 2 months ago


Please show me how exactly you import these files? Is this a pure JS project, or do you use a framework or bundler such as Laravel or Webpack?



Please insert min. 20 characters.

FREE CONSULTATION

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

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 7.3.2
  • Device: laptop
  • Browser: chrome
  • OS: win11
  • Provided sample code: No
  • Provided link: No
Tags