在 Bootstrap 轮播的活动幻灯片中查找元素

finding element in the active slide of Bootstrap carousel

我正在尝试对 Bootstrap 3 旋转木马中的 div 做一些事情。但是,我如何找到 div?

 $('.carousel').on('slid.bs.carousel', function () {
    var carouselData = $(this).data('bs.carousel');
              var currentIndex = carouselData.getItemIndex(carouselData.$element.find('.item.active'));

    //now I know the current item, but how do I change the .description div
    //inside that item?


    });

为什么不使用 carouselData.getItemIndex 而不是直接操作该元素?

carouselData.$element.find('.item.active .description').text("New content here");

您的解决方案即将完成。对于寻找解决方案并登陆此处的任何人:

$('.carousel').on('slid.bs.carousel', function (e) {
  // mind the e parameter I added               ^ here
  var carouselData = $(this).data('bs.carousel');
  var currentIndex = carouselData.getItemIndex($(e.relatedTarget));

  // but that is unnecessary because the current slide is in e.relatedTarget
  var currentItem = $(e.relatedTarget);
  // currentItem is the current slide's div, use it
});