简体   繁体   中英

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

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" class="modal">
<div class="modal-content">
</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?

You should include jquery first before the library

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM