<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
body {
background: white;
color: #323232;
font-weight: 300;
height: 100vh;
margin: 0;
display: flex;
align-items: center;
justify-content: center;
text-align: center;
font-family: Helvetica neue, roboto;
}
img {
width: 56px;
height: 48px;
}
h1 {
font-weight: 200;
font-style: 26px;
margin: 10px;
}
.item {
width: 100px;
height: 100px;
background: orange;
cursor: pointer;
margin-right: 10px;
}
.active {
background: red;
}
const items = document.querySelectorAll('.item');
items.forEach(item => {
item.addEventListener('click', function() {
items.forEach(elem => elem.classList.remove('active'));
this.classList.add('active');
});
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.