我正在使用bootstrap carousel,我希望能够删除包含活动类的图像容器上的类d-none
,所以我有
$(".carousel-control").click(function() {
$(".work-c-box").addClass('d-none');
var focusedEl = $(".carousel-inner").find(".active .work-c-image .work-c-box:nth-child(2)");
focusedEl.removeClass('d-none');
如果我在Dev Tools中检查它会删除d-none类,但不会删除我的焦点[active],它会从之前单击事件中处于该条件的元素中删除它。
我尝试使用.prev()函数,但没有运气,或者对问题有很好的理解:)
这是HTML部分
<div id="carousel-1" class="carousel slide multi-item-carousel" data-ride="carousel" data-interval="false">
<div class="carousel-inner">
<div class="item active">
<div class="item__third work-c-image">
<img src="image.jpg" alt="" >
<div class="work-c-box">
<h3>some Heading</h3>
<p>dummy text</p>
</div>
</div>
</div>
<div class="item">
<div class="item__third work-c-image">
<img src="image2.jpg" alt="">
<div class="work-c-box box-hide">
<h3>some heading</h3>
<p>dummy text</p>
</div>
</div>
</div>
<div class="item">
<div class="item__third work-c-image">
<img src="image3.jpg" alt="" >
<div class="work-c-box box-hide">
<h3>some heading</h3>
<p>dummy text</p>
</div>
</div>
</div>
</div>
<a href="#carousel-1" class="left carousel-control" role="button" data-slide="prev"></a>
<a href="#carousel-1" class="right carousel-control" role="button" data-slide="next"></a>
</div>
</div>
我需要的是一些暗示和解释,而不仅仅是用一些代码回答我的问题。
谢谢
你可以使用下面的代码
$($(".carousel-inner").find(".active .work-c-image .work-c-box:nth-child(2)").parent().parent()).removeClass('active');