Home > Blockchain >  $(...).modal is not a function when using jQuery Modal plugin
$(...).modal is not a function when using jQuery Modal plugin

Time:12-01

I'm using this jQuery Modal Plugin to show a popup on my site.

When the page loads, I want to delay the popup by 5 seconds, but is not working together with the "setTimeout" method.

Here is my HTML:

<div id="ex1" >
<div >
</div>
</div>

JS:

setTimeout(() => {
 $('#ex1').modal({
    fadeDuration: 500,
    showClose: false
 );
}, 5000)

Does anyone knows how to fix this?

So whenever I use the "setTimeout" method, I get this error: "Uncaught TypeError: $(...).modal is not a function", but it works fine without it.

Edit: I also noticed that is not working when I try to call it inside of window.onload = function() {}

How can I make this work?

CodePudding user response:

You should include jquery first before the library

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>

CodePudding user response:

There are some errors in the console coming from jQuery that I have to fix, and most likely this is the problem because I tried a pure JS library and it works just fine.

  • Related