Я бы использовал переключатели
<label><input type="radio" name="pl-1-avatar" value="a"> <span>A</span></label>
<label><input type="radio" name="pl-1-avatar" value="b"> <span>B</span></label>
<label><input type="radio" name="pl-2-avatar" value="a"> <span>A</span></label>
<label><input type="radio" name="pl-2-avatar" value="b"> <span>B</span></label>
, чем JavaScript, чтобы определить, кто есть кто go для:
const pl1avatar = document.querySelector('[name="pl-1-avatar"]:checked').value;
const pl2avatar = document.querySelector('[name="pl-2-avatar"]:checked').value;
и CSS:
[name$="-avatar"]:checked ~ span { /* SELECTED STYLE HERE */ }
Время демонстрации:
const getAvatars = () => {
const pl1avatar = document.querySelector('[name="pl-1-avatar"]:checked').value;
const pl2avatar = document.querySelector('[name="pl-2-avatar"]:checked').value;
console.log(`
PLAYER 1 AVATAR: ${pl1avatar}
PLAYER 2 AVATAR: ${pl2avatar}
`);
}
document.querySelector("#play").addEventListener('click', getAvatars);
[name$="-avatar"] {
position: absolute;
opacity: 0;
}
[name$="-avatar"] ~ span {
display: inline-block;
padding: 10px;
background: #eee;
}
[name$="-avatar"]:checked ~ span {
box-shadow: 0 0 0 2px blue;
}
PLAYER 1<br>
<label><input type="radio" name="pl-1-avatar" value="a" checked> <span>A</span></label>
<label><input type="radio" name="pl-1-avatar" value="b"> <span>B</span></label>
<label><input type="radio" name="pl-1-avatar" value="c"> <span>C</span></label>
<hr>
PLAYER 2<br>
<label><input type="radio" name="pl-2-avatar" value="a" checked> <span>A</span></label>
<label><input type="radio" name="pl-2-avatar" value="b"> <span>B</span></label>
<label><input type="radio" name="pl-2-avatar" value="c"> <span>C</span></label>
<hr>
<button id="play">START GAME</button>