title: Jump to last slide on Bootstrap carousel
body: <p>I'm creating a Carousel with bootstrap and I'd like to create a link that jump directly to the last slide in the carousel (with <em>n</em> slides, not a fixed number). I tried to resolve the problem assigning the class <code>active</code> to the last <code>div</code> in the this way: </p>
  
  <pre><code>$(".last").click(function(){
      $('myCarousel div').removeClass('active'); 
      $('myCarousel div:last-child').addClass('active'); 
  });
  </code></pre>
  
  <p>But, this works if I have just a carousel in my page, but if the carousels are more than one the link go to the last slide on all the carousels. How can I resolve the problem? Here is an example of the code:</p>
  
  <pre><code>&lt;div id="myCarousel1" class="carousel slide"&gt; 
   &lt;div class="carousel-inner" role="listbox"&gt;
     &lt;div class="item active slide"&gt;
      &lt;img src="http://placehold.it/350x150"&gt;
     &lt;/div&gt;
     […] other items
   &lt;/div&gt;    
  &lt;/div&gt;
  &lt;ul&gt;
   &lt;a href="#myCarousel1" data-slide="prev"&gt;&lt;li&gt;Prev&lt;/li&gt;&lt;/a&gt;
   &lt;a href="#myCarousel1" data-slide="next"&gt;&lt;li&gt;Next&lt;/li&gt;&lt;/a&gt;
   &lt;a href="#myCarousel1"&gt;&lt;li class="last"&gt;Last&lt;/li&gt;&lt;/a&gt;
  &lt;/ul&gt; 
  
  &lt;div id="myCarousel2" class="carousel slide"&gt; 
   &lt;div class="carousel-inner" role="listbox"&gt;
     &lt;div class="item active slide"&gt;
      &lt;img src="http://placehold.it/350x150"&gt;
     &lt;/div&gt;
     […] other items
   &lt;/div&gt;    
  &lt;/div&gt;
  &lt;ul&gt;
   &lt;a href="#myCarousel2" data-slide="prev"&gt;&lt;li&gt;Prev&lt;/li&gt;&lt;/a&gt;
   &lt;a href="#myCarousel2" data-slide="next"&gt;&lt;li&gt;Next&lt;/li&gt;&lt;/a&gt;
   &lt;a href="#myCarousel2"&gt;&lt;li class="last"&gt;Last&lt;/li&gt;&lt;/a&gt;
  &lt;/ul&gt; 
  
  &lt;script&gt; 
  $(document).ready(function(){
   $(".last").click(function(){
    $('[id^="myCarousel"] div').removeClass("active"); 
    $('[id^="myCarousel"] div:last-child').addClass("active"); 
   });      
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>Thanks! </p>