title: How can autoplay current carousel accordion tab video using flickity library and bootstrap accordion tabs?
body: <p>I'm working in carousel sliders located in accordion tabs using bootstrap 5 and flickity. I have seven accordion tabs. Every accordion tab contain a carousel slider with autoplay videos.
  works great the autoplay video in first accordion carousel, but only works in the first accordion tab, i don't know how make it work on the rest accordion tabs, I was thinking to create an array of id but this idea didn't work, also tried to use document.querySelectAll() with all ids of the tabs but this didn't work either. The script to make the first tab accordion work with carousel is this.</p>
  <pre><code>      (function(){
  const target1 = document.getElementById('flickity1');  
  const videos = target1.getElementsByTagName('video');
  const videosLength = videos.length;
  </code></pre>
  <p>//start the first video in the carousel</p>
  <pre><code>videos[0].play();
  
  const flickity = new Flickity(target1,{
    wrapAround:false,
    autoPlay:false,
    on: {
      ready: function() {
        console.log('Flickity ready');
        videos[0].play();
      }
    }
  });
  flickity.on('settle',changeSlide);
    function changeSlide(index) {
  for(let i = 0;i &lt; videosLength; i++){
    videos[i].currentTime = 0;
    videos[index].play();
  }
    }
  }());
  </code></pre>
  <p>One solution that I found is repeating for the differents ids the same script but changing the name variable for example const target2 = document.getElementById('flickity2'); and so on... But this not the correct way to do this. I thinks that an array can work.
  something like this:</p>
  <pre><code>var ids = ['flickity0', 'flickity1'];
  function accorcarousel() {
  for (var i = 0; i&lt;ids.length; i++){
  document.getElementById(ids[i]) = target1;}}
  </code></pre>
  <p>I was reading the bootstrap docs that i can trigger the function via data attributes.
  data-bs-toggle=&quot;collapse&quot; and a data-bs-target to the element to automatically assign control of one or more collapsible elements.
  Any idea is very appreciate.</p>