const images = document.querySelectorAll('.thumbnail');
images.forEach(img => {
img.addEventListener("mouseover", ()=> {
img.classList.add('blur')
img.parentElement.style.outline = "2px solid hsl(26, 100%, 55%)";
img.parentElement.style.borderRadius = "12px";
})
img.addEventListener("mouseout", ()=> {
img.classList.remove('blur')
img.parentElement.style.outline = "";
})
});
.left-section-bottom{
display: flex;
width: 80%;
margin: 32px auto;
gap: 40px;
}
.left-section-bottom img{
border-radius: 12px;
}
.thumbnail.blur{
opacity: 0.4;
cursor: pointer;
}
.thumbnail-div{
display: flex;
}
<div class="left-section-bottom">
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
<div class="thumbnail-div"><img class="thumbnail" src="images/image-product-1-thumbnail.jpg" alt=""></div>
</div>
I was searching for a solution to the same problem and after some trial and error, I managed to get it working. The initial challenge is linked here:
With four images, iterate through them individually using querySelectorAll instead of querySelector.
Make use of forEach() to loop through your thumbnail images.
As suggested by Kingsly, wrap your images in a div to apply styles to the div rather than the blurred images themselves.
If you add your images, this code snippet should work seamlessly.