Upon document.ready, I am defining several functions, then attempting to call them using window[variable], where the variable is the name of the function. I came upon this soution here: Calling a JavaScript function named in a variable. Here is my code:
jQuery(document).ready(function() {
function playSlide0(){
player0.playVideo();
console.log('slide0 fired');
}
function playSlide1(){
player1.playVideo();
console.log('slide1 fired');
}
function playSlide2(){
player2.playVideo();
console.log('slide2 fired');
}
swiper.on('slideChangeStart', function () {
var currentSlide = swiper.activeIndex;
var currentVid = document.getElementById('video'+currentSlide);
var currentVidId = 'slide_'+currentSlide;
var playSlideFunction = 'playSlide'+currentSlide;
window[playSlideFunction]();
});
});
Instead of calling my function, I am getting the error 'window[playSlideFunction] is not a function'. Any thoughts? Thank you.