try it
http://jsfiddle.net/f7hpoyfj/1/
For color comparison you need to use if (element.css("background-color") == "rgba(0, 0, 0, 0)") . It may or may not be browser dependent. Not sure.
Also, look how I created the loop - you did not use i in your previous function, which, in my opinion, is a mistake, since you effectively compared the same element over and over again.
for (var i = 7; i > 1; i--) { var element = $('table tr:nth-child(' + i + ') td:nth-child(' + column + ')'); if (element.css("background-color") == "rgba(0, 0, 0, 0)" || element.css("background-color") == "transparent" || element.css("background-color") == "white") { element.css("background-color", playerTurn); break; } }
source share