I have a bootstrap carousel featuring 3 images, each with a caption. My goal is to make it so that when you click on the caption of the first carousel image, the image will change to a gif. I've attempted to achieve this using basic JavaScript, but so far it's not working.
Specifically, I want the 'plymouthImg' to transition into 'permitionImg'. Currently, the display for 'permitionImg' is set to none!important
.
<div id="carouselExampleCaptions" class="carousel slide" data-bs-ride="carousel">
<div class="carousel-inner">
<div class="carousel-item active">
<img id="plymouthImg" src="imgs/plymouth1.jpg" class="d-block w-100" alt="Roland Levinsky Building">
<img id="permitionImg" src="imgs/plymouthbaw.gif" class="d-block w-100" alt="Permition">
<div class="carousel-caption d-md-block">
<h3 onclick="changeText()" class="plymouth">Welcome to the University of Plymouth</h3>
<h3 class="permition">Welcome to Permition</h3>
</div>
</div>
This is the JavaScript function on the h3:
function changeText() {
const plymouthText = document.querySelector('.plymouth');
const permitionText = document.querySelector('.permition');
const plymouthImg = document.getElementById('plymouthImg');
const permitionImg = document.getElementById('permitionImg');
plymouthText.style.display = "none";
permitionText.style.display = "block";
plymouthImg.style.display = "none!important";
permitionImg.style.display = "block!important";
}