I'm making a modal the background image of which should change every time the user clicks to the next image. The background image is just a gradient. To be able to make the background image transparent without affecting the foreground, I had to create a pseudoclass, which works. However hard I try, I cannot get the background image in the pseudoclass to change as the user clicks. I cannot figure out what I am doing wrong, but I suspect the problem is in this part of the javascript:
if(slides[slideIndex] === 1){
document.getElementsByClassName("modalE:before").src.style.backgroundImage = "linear-gradient(160deg, #ff2652, #008ce3)";
}
I could use some help making the background image change as the user clicks through images.
function showSlides(n) {
var slides = document.getElementsByClassName("mySlidesE");
var i = 0;
if (n > slides.length) {slideIndex = 1
}
if (n < 1) {slideIndex = slides.length}
for (i = 0; i < slides.length; i++)
{
slides[i].style.display = "none";
}
slides[slideIndex-1].style.display = "block";
if(slides[slideIndex] === 1){
document.getElementsByClassName("modalE:before").src.style.backgroundImage = "linear-gradient(160deg, #ff2652, #008ce3)";
}
}
.modalE {
display: none;
position: fixed;
z-index: 1;
}
.modalE:before {
content: ' ';
display: block;
background-image: linear-gradient(160deg, #ff2652, #008ce3);
opacity: .6;
}
.mySlidesE {
position: relative;
display: none;
}
<div id="EricModal" class="modalE modalE:before">
<span class="closeE" onclick="closeModalE()">×</span>
<div class="modal-contentE">
<div class="mySlidesE">
<img src="" style="width:100%">
</div>
<div class="mySlidesE">
<img src="" style="width:100%">
</div>
<div class="mySlidesE">
<img src="" style="width:100%">
</div>
<div class="mySlidesE">
<img src="" style="width:100%">
</div>
<div class="mySlidesE">
<img src="" style="width:100%">
</div>
<!-- Next/previous controls -->
<a class="prevE" onclick="plusSlides(-1)">❮</a>
<a class="nextE" onclick="plusSlides(1)">❯</a>