6

i like to use the Bootstrap carousel slider. Is it possible to start the slider without the active class in the first Image? The code is set with TYPOSCRIPT and i can not set the first item to active. Is there a way with JavaScript?

Thanx for help

Christian

HTML Code

<div class="carousel slide article-slide" id="myCarousel">
    <div class="carousel-inner cont-slider">
        <div class="item">
          <img class="img-responsive" src="http://placehold.it/800x300/cccccc/ffffff">
        </div>
       <div class="item">
          <img class="img-responsive" src="http://placehold.it/800x300/999999/cccccc">
        </div>
        <div class="item">
          <img class="img-responsive" src="http://placehold.it/800x300/dddddd/333333">
        </div>              
    </div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272
schani
  • 61
  • 1
  • 1
  • 2

1 Answers1

6

Yes, you can add class like this (using jQuery):

$(document).ready(function () {
  $('#myCarousel').find('.item').first().addClass('active');
});
max
  • 8,632
  • 3
  • 21
  • 55
  • 1
    For BS4 it's `$('#myCarousel').find('.carousel-item').first().addClass('active');` – Ugo Aug 21 '20 at 11:21