Is there a way to improve the code below so that the background color of this div box changes instantly when clicked, without needing to click twice?
function updateBackgroundColor(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='updateBackgroundColor(this.id)' id='".$row['platz_id']."'>".$counter."</div>