showing results for - "dynamically add images to carousel"
Paolo
21 May 2017
1<------------------------------------ HTML ------------------------------------>
2<div id="carousel-example-generic" class="carousel slide" data-ride="carousel">
3  <!-- Indicators -->
4  <ol class="carousel-indicators"></ol>
5  <!-- Wrapper for slides -->
6  <div class="carousel-inner"></div>
7  <!-- Controls -->
8  <a class="left carousel-control" href="#carousel-example-generic" data-slide="prev">
9    <span class="glyphicon glyphicon-chevron-left"></span>
10  </a>
11  <a class="right carousel-control" href="#carousel-example-generic" data-slide="next">
12    <span class="glyphicon glyphicon-chevron-right"></span>
13  </a>
14</div>
15<------------------------------------ JS ------------------------------------>
16$(document).ready(function(){  
17  for(var i=0 ; i< m.length ; i++) {
18    $('<div class="item"><img src="'+m[i]+'"><div class="carousel-caption"></div>   </div>').appendTo('.carousel-inner');
19    $('<li data-target="#carousel-example-generic" data-slide-to="'+i+'"></li>').appendTo('.carousel-indicators')
20
21  }
22  $('.item').first().addClass('active');
23  $('.carousel-indicators > li').first().addClass('active');
24  $('#carousel-example-generic').carousel();
25});