Я делаю игру «камень, ножницы, бумага» с помощью HTML, CSS и JS DOM. У меня есть 6 кнопок, которые позволяют вам выбрать, сколько раундов вы хотите сыграть. Я хочу, чтобы при нажатии на один из них он становился темнее. Затем, когда вы щелкнете по другому, он станет темнее, а предыдущий станет более светлым. Кто-нибудь знает, как бы я это реализовал? Любая помощь будет принята с благодарностью :)
// Changes button color when clicked
let rounds = document.querySelectorAll(".rounds");
rounds.forEach(i => {
i.addEventListener("click", () => {
i.style.cssText = "color: gray; border-color: gray";
});
});
* {
color: white;
box-sizing: border-box;
margin: 0;
padding: 0;
}
body {
background-color: black;
font-family: Arial, Helvetica, sans-serif;
}
#rounds {
display: grid;
justify-content: center;
grid-template-columns: repeat(3, 0.2fr);
grid-template-rows: repeat(2, 0.2fr);
grid-gap: 10px;
margin-top: 30px;
}
.rounds {
background-color: black;
font-size: 25px;
border: solid 8px white;
outline: none;
padding: 5px 0;
}
.rounds:hover {
cursor: pointer;
color: lightgray;
border-color: lightgray;
}
<div id="rounds">
<button class="rounds">Best of 1</button>
<button class="rounds">Best of 3</button>
<button class="rounds">Best of 5</button>
<button class="rounds">Best of 7</button>
<button class="rounds">Best of 10</button>
<button class="rounds">Custom</button>
</div>