-3

How I can auto increment vidslide1.stopVideo(); in javascript?

Example,

vidslide1.stopVideo();

vidslide2.stopVideo();

vidslide3.stopVideo();

...

vidslide10.stopVideo();

Script:

 $('#myCarousel').on('slide.bs.carousel', function () {
        vidslide1.stopVideo();  
        vidslide2.stopVideo();
        });
Deepak Singh
  • 129
  • 2
  • 12
  • 4
    create an array containing vidslides and refer by index – mehulmpt May 09 '17 at 11:56
  • The suggested way is to use arrays. Although you could use the eval() function, like explained in another StackOverlow answer: http://stackoverflow.com/a/5117162/2312381 – Felix May 09 '17 at 12:01
  • Where are these defined? – charlietfl May 09 '17 at 12:01
  • I was trying something like this var i for(i = 0; 1 < vidslides.length(); i++) { var obj = vidslides[i] vidslide(i).stopVideo(); } but not working. and breaking the slider cycle. – Deepak Singh May 09 '17 at 12:05

1 Answers1

2

Welcome to arrays

var vidarr = [vidslide1,vidslide2,vidslide3];
vidarr.forEach(function(v) { v.stopVideo(); });
Jamiec
  • 133,658
  • 13
  • 134
  • 193