Home > Enterprise >  Jquery $(...).modal is not a function
Jquery $(...).modal is not a function

Time:02-22

I'm keep getting the Jquery $(...).modal is not a function error.

I know this error happens if jquery isn't loaded. My thing is i'm very sure it's loaded in correctly.

In my _Layout i load a partial named "_LayoutDefaultHead".

<head>
    @Html.Partial("_LayoutDefaultHead")
    @Html.Partial("_Head")
</head>

In that partial i'm loading jquery.

<script src="/scripts/jquery.js"></script>
<script src="/scripts/jquery.adnsfalias.js"></script>
<script src="/Scripts/lazysize.min.js" async></script>

On the bottom of the _Layout i'm loading another partial named "_LayoutDefaultBodyClose";

@Html.Partial("_LayoutDefaultBodyClose")

In this partial i'm calling a function which uses $(...).Modal.

@Html.Raw(ACMT_Helpers.GetPopup())

    ($('#popup-"   ID   "-modal').modal('show');sessionStorage['popup-"   ID   "-modal'] = 'true';)

Even tho i loaded Jquery way earlier it isn't loaded in the "_LayoutDefaultBodyClose" and i can't see why.

Does someone know what i'm doing wrong?

Here's the sourcecode so you can see it's almost impossible that it doesn't work:

On line 1980 bootstrap gets included. On line 1990 is a document ready and on 1991 it's throwing the error.

enter image description here

The function .modal() even gets used earlier on line 1838.

enter image description here

Jquery is already loaded on line 54.

enter image description here

CodePudding user response:

The problem was with the new bootstrap version cause it changed to vanillajs instead of jquery like the older versions. It says that you can still use it with jquery but it only works in the console after the page is loaded and not yet with .ready. I fixxed the issue just with using an older version of bootstrap.js. I know not the best solution but i can't waste more time with that problem.

  • Related