A simple way is to check the current color and change based on it. The code is close to your current:
function Selecionar(){
var selecionado = document.getElementById("poltronas");
// Se estiver amarelo, troca pra verde
if(selecionado.style.background === "yellow") {
selecionado.style.background = "green";
// Senão, troca pra amarelo
} else {
selecionado.style.background = "yellow";
}
}
This will work if the initial color is set to yellow, by JS or inline style:
<div id="poltronas" style="background: yellow"></div>
Without this the initial color would be undefined from the point of view of this script, and the first click would define yellow. From there it would work normally.
Random or preset colors?
– Valdeir Psr
green and yellow presets, when not in one color have to be in the other
– Bruna