<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
body {
display: grid;
grid-template-columns: repeat(3, 1fr );
}
.item {
width: 200px;
height: 100px;
background-color: gray;
}
.item.active {
background-color: red;
}
let items = document.querySelectorAll('.item');
items.forEach(function(item) {
item.addEventListener("click", () =>{
item.classList.add('active');
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.