One of the features on my website includes 3 blocks with buttons. These buttons trigger a change in the displayed picture when clicked. However, it is crucial to ensure that when a new track is activated, the previous button returns to its original state.
https://i.sstatic.net/AFsS0.png
let buttons = document.querySelectorAll('.btn-wrapper');
buttons.forEach(function(button) {
button.addEventListener('click', function(e) {
button.querySelector('.play__btn').classList.toggle('play__btn-hidden');
button.querySelector('.pause__btn').classList.toggle('pause__btn-active');
})
})
.flex {
display: flex;
align-items: center;
}
.card__title {
margin-right: 20px;
}
.btn {
width: 17px;
height: 17px;
cursor: pointer;
}
.play__btn-hidden {
display: none;
}
.pause__btn {
display: none;
}
.pause__btn-active {
display: block;
}
<div class="cards">
<div class="card flex">
<h4 class="card__title">Track 01</h4>
<div class="btn-wrapper">
<img src="https://cdn-icons-png.flaticon.com/512/153/153752.png" alt="" class="play__btn btn">
<img src="https://cdn-icons-png.flaticon.com/512/1214/1214679.png" alt="" class="pause__btn btn">
</div>
</div>
<div class="card flex">
<h4 class="card__title">Track 02</h4>
<div class="btn-wrapper">
<img src="https://cdn-icons-png.flaticon.com/512/153/153752.png" alt="" class="play__btn btn">
<img src="https://cdn-icons-png.flaticon.com/512/1214/1214679.png" alt="" class="pause__btn btn">
</div>
</div>
<div class="card flex">
<h4 class="card__title">Track 03</h4>
<div class="btn-wrapper">
<img src="https://cdn-icons-png.flaticon.com/512/153/153752.png" alt="" class="play__btn btn">
<img src="https://cdn-icons-png.flaticon.com/512/1214/1214679.png" alt="" class="pause__btn btn">
</div>
</div>
</div>