First time poster - have tried to find solution elsewhere but not able to.
I have created a grid of buttons. Upon clicking button 1, I want the background to change to a preset colour. When another button is clicked (button 2), I would like the button(1) background to change back to the original, followed by the newly clicked button (button 2) to take on the preset colour.
Here is the HTML written so far:
<div class="tip-select">
<p class="ttext">Select Tip %</p>
<div class="tip">
<div class="five-tip btn tips">5%</div>
<div class="ten-tip btn tips">10%</div>
<div class="fifteen-tip btn active-tip tips">15%</div>
<div class="twentyfive-tip btn tips">25%</div>
<div class="fifty-tip btn tips">50%</div>
<div class="custom btn tips">Custom</div>
</div>
</div>
Here is the Javascript written so far:
tips.forEach(function (mov) {
mov.addEventListener("click", handleClick);
});
function handleClick(event) {
tips.forEach(function (val) {
if (event.target.innerHTMl == val.innerHTMl) {
val.classList.add("active-tip");
console.log(val);
}
});
}
Here is the current design for reference:

My thought is to iterate through the nodelist and assign active-tip as a class based on the button selected. At the moment though all of the buttons are changing colour when clicked.