I am using Glide.js to display sliders on my website. To display one slide, I am using the following code:
document.querySelector(".resources-carousel") &&
((resourcesCarousel = new Glide(".resources-carousel", {
type: "slider",
perView: 4,
gap: 20
})),
resourcesCarousel.mount());
On another page, I would like to display multiple sliders using this code:
var resourceSliders = document.querySelectorAll('.resources-carousel');
for (var i = 0; i < resourceSliders.length; i++) {
var glide = new Glide(resourceSliders[i],{
type:"slider",
perView:4,
gap:20,
});
glide.mount();
}
The code works fine and initialises both sliders when pasted in to the console, however when I add this code to my scripts.js file in Wordpress I get the following error:
Uncaught SyntaxError: Unexpected token 'var'
How can I fix this?