I have a group of images and each image has a title I want to change the background and title of each image to a different color on hover.
Now I selected my images and titles and looped throw them to change their colors but its not working I am not surprised just want to know how to fix it.
function changeBgAndTitle(element, event, backgroundColor, titleColor) {
element.addEventListener(event, () => {
const projectThumbnail = document.querySelectorAll('.projects-list img');
const projectTitle = document.querySelectorAll('article h1');
for (i = 0; i < projectThumbnail.length; i++) {
console.log(projectThumbnail[0]);
}
for (i = 0; i < projectTitle.length; i++) {
projectTitle[i].style.color = titleColor;
}
})
}
changeBgAndTitle(projectThumbnail[0], 'mouseover', '#0090d8', 'white');
<div class="projects-list">
<article class="old-and-blue">
<h1>old and blue</h1>
<figure>
<a href="/old-and-blue.html" class="noclick">
<img src="assets/media/images/slides/old-and-blue.jpg" alt="">
</a>
</figure>
</article>
<article class="dably">
<h1>dably</h1>
<figure>
<a href="/old-and-blue.html">
<img src="assets/media/images/slides/dably.jpg" alt="">
</a>
</figure>
</article>
<article class="cairo">
<h1>cairo</h1>
<figure>
<a href="/old-and-blue.html">
<img src="assets/media/images/slides/cairoe.jpg" alt="">
</a>
</figure>
</article>
<article class="cta">
<h1>cta</h1>
<figure>
<a href="/cta.html">
<img src="assets/media/images/slides/cta.jpg" alt="">
</a>
</figure>
</article>
</div>
projectThumbnail[0]should beprojectThumbnail[i]. Also, you should declareias a local variable."in<a href="/cta.html" ">. That could be screwing up the rest of your HTML. Is that a copying error or in the real code?