0

I am trying to to get id of the image of the carousel that will be the active item. That is I am trying to get of the image id of the slide event. Currently, I have:

function ModalImageCaption () {
   var activeImage =
   $('.carousel').on('slide.bs.carousel', function(event){
       var imageId = $(event.relatedTarget).find('.carousel-inner');
       console.log (imageId);
   });
}

The console log implies that there are children nodes one of them being the image child so I update imageId variable to

var imageId=$(event.relatedTarget).find('.carousel-inner').children('img').attr('id'); 

but it always comes back as undefined is there something I am missing?

user69001
  • 47
  • 1
  • 8

1 Answers1

0

You can try to do:

$('.gallery-carousel').data("bs.carousel").getActiveIndex()

or

getItemIndex()

after 3.2

from:

Twitter Bootstrap Carousel - access current index

And:

https://github.com/twbs/bootstrap/pull/2404#issuecomment-4589229

Community
  • 1
  • 1
Destrif
  • 2,104
  • 1
  • 14
  • 22
  • No, unfortunately that did not work for me. I tired the direct copy and paste version of your suggestion, then I tried different variations of it. Even if it did I don't think it would have gotten the correct slide as the active slide as far as I can tell doesn't change until the very end of the event. Whereas I trying to get the slide that will soon to be active. – user69001 Jun 03 '16 at 15:19
  • Did you try all solution from github website given? like this. $(".carousel").on('slid', function(e){ $(".active", e.target).index()}) – Destrif Jun 03 '16 at 15:22