I have a bunch of divs with the same class name and I want the background colour of one of the divs to change when I hover on it but when I hover on one, all the others change as well.
I tried turning the nodelist into an array then looping over the array but it still doesn't work.
This is what I have please help me improve on it or show me another way to acheive what want
I would use the CSS .card-content:hover:{display:flex}
but the original display is set to none so there is nothing to hover on
function showContent() {
const card = document.querySelectorAll('.card-content');
// for (let i = 0; i < card.length; i ) {
// card[i].classList.toggle("show")
// }
// // this.style.display= "flex";
// for (const show of card) {
// console.log(show)
// }
// let cards = [card]
// console.log(cards)
var arr = [];
for(var i = card.length; i--; arr.unshift(card[i]));
// console.log(arr)
for (let j = 0; j < arr.length; j ) {
const show = arr[j];
show.style.display= "flex";
}
}
.project.container{
width: 60%;
display: flex;
background-color: black;
padding: 2vw 5vw;
justify-content: space-between;
flex-wrap: wrap;
}
.project .project_card {
width: calc(50% - 2vw);
margin: 1vw 1vw;
text-align: center;
height: 200px;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
background-color: violet;
}
.project .project_card.card1{
background-image: url('../thumbs/dwyw.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.project .project_card.card2{
background-image: url('../thumbs/courselist.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.project .project_card.card3{
background-image: url('../thumbs/iqoption.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.project .project_card.card4{
background-image: url('../thumbs/slider.png');
background-size: cover;
background-position: center;
background-repeat: no-repeat;
}
.project .project_card .card-content{
background-color: #898987fa;
height: 200px;
width: 100%;
padding: 2vw;
flex-direction: column;
align-items: center;
justify-content: center;
display: none;
}
.show{
display: flex;
}
.project .project_card .card-content a{
background: linear-gradient(to right, #242424b0,#000000c0);
padding: 1vw 2vw;
text-decoration: none;
font-family: 'Montserrat', sans-serif;
position: relative;
font-weight: 700;
font-size: 1.2vw;
transition: all 0.5s;
border-radius: 5px;
overflow: hidden;
box-shadow: 0px 5px 5px 1px rgba(0,0,0,0.58);
-webkit-box-shadow: 0px 5px 5px 1px rgba(0,0,0,0.58);
-moz-box-shadow: 0px 5px 5px 1px rgba(0,0,0,0.58);
}
.project .project_card .card-content a:hover{
background: linear-gradient(to right, #000000c0, #242424b0);
}
<div class="project container">
<div class="project_card card1" onmouseover="showContent()">
<div class="card-content">
<h3 class="name">{%NAME%}</h3>
<p class="desc">{