Uncaught ReferenceError, Splide is not defined at HTMLDocument

Viewed 4700

I have written code for thumbnail slider following an example in the following link splidejs.com/getting-started for primary slider. Tried to look again and again but I don't see anything in the output even pictures are not shown. Header files already linked through CDN(CSS and js)

Below is the code:

HEADER FILES

 <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@splidejs/splide@latest/dist/css/splide.min.css">

 <script type="text/javascript" src="catalog.js"></script>
 <link rel="stylesheet" type="text/css" href="catalog.css">

JS HEADER FILE script src="https://cdn.jsdelivr.net/npm/@splidejs/splide@latest/dist/js/splide.min.js">

HTML CODE

 <div class="splide">
  <div class="splide__track">
   <ul class="splide__list">
     <li class="splide__slide"><img src="pic2.jpg"></li>
     <li class="splide__slide"><img src="pic1.jfif"></li>
     <li class="splide__slide"><img src="">pic.png</li>
   </ul>
 </div>

JAVASCRIPT CODE

document.addEventListener( 'DOMContentLoaded', function () {
new Splide( '#secondary-slider', {
    fixedWidth : 100,
    height     : 60,
    gap        : 10,
    rewind     : true,
    cover      : true,
    pagination : false,
} ).mount();

} );

2 Answers

From what I see in your javascript code you are trying to mount Splide on "#secondary-slider" but I can't see this id in your HTML. Try fixing this with either adding an a corresponding id property to your div with with class "splide" or call Splide mount on ".splide"

Related