I’m trying to change the background color of this div box whenever it gets clicked. For some reason the funtcion only works whenever I click on the same div box twice. Am I missing something?
function selected_platz(platz_id)
{
if(document.getElementById(platz_id).style.backgroundColor == "rgb(0, 168, 0)")
{
document.getElementById(platz_id).style.backgroundColor = "blue";
return;
}
document.getElementById(platz_id).style.backgroundColor = "rgb(0, 168, 0)";
}
<div class='div_platz' onclick='selected_platz(this.id)' id='".$row['platz_id']."'>".$counter."</div>