I am having an issue with my Bootstrap 4 carousel. I am attempting to make the carousel caption only display when hovered over, but nothing is showing up when I hover over the image.
There are no error messages in the console, so it's unclear what I may have overlooked. One potential cause I considered was the carousel sliding automatically, but even after removing that feature, the caption still does not appear on hover.
The Carousel:
<div id="NewsCarousel" class="carousel slide default-div-top-padding" data-ride="carousel">
<!-- Indicators -->
<ul class="carousel-indicators">
<li data-target="#NewsCarousel" data-slide-to="0" class="active"></li>
<li data-target="#NewsCarousel" data-slide-to="1"></li>
<li data-target="#NewsCarousel" data-slide-to="2"></li>
</ul>
<!-- The slideshow -->
<div class="carousel-inner">
<div class="carousel-item active">
<img src="~/images/Resources/HomePage/knowledgeLatestNews.jpg" alt="imgAlt" style="width:650px;height:350px">
<div class="carousel-caption">
<a href="#"><h3>Los Angeles</h3></a>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="~/images/Resources/HomePage/knowledgeLatestNews.jpg" alt="imgAlt" style="width:650px;height:350px">
<div class="carousel-caption">
<a href="#"><h3>Los rtr</h3></a>
<p>We had such a great time in LA!</p>
</div>
</div>
<div class="carousel-item">
<img src="~/images/Resources/HomePage/knowledgeLatestNews.jpg" alt="imgAlt" style="width:650px;height:350px">
<div class="carousel-caption">
<a href="#"><h3>Los Angeasdales</h3></a>
<p>We had such a great time in LA!</p>
</div>
</div>
</div>
<!-- Left and right controls -->
<a class="carousel-control-prev" href="#NewsCarousel" data-slide="prev">
<span class="carousel-control-prev-icon"></span>
</a>
<a class="carousel-control-next" href="#NewsCarousel" data-slide="next">
<span class="carousel-control-next-icon"></span>
</a>
</div>
Javascript:
<script type="text/javascript">
$(document).ready(function () {
$('.carousel-caption').hide();
$('img[alt = imgAlt').on('hover', function () {
$('.carousel-caption').fadeIn();
});
});
</script>
I'm unsure of what I may have missed in my JavaScript code. Additionally, if there is a cleaner or better way to achieve this effect using only CSS, any suggestions would be greatly appreciated.
Thank you in advance.