I am making a simple game where you and a partner have to draw something by taking turns clicking <td>
tags. Right now I can click a <td>
and it will turn black but it is supposed to turn white on a second click. The second .click works, I know this because 0 and 1 will alert but not 2.
$("td").click(function(){
alert(0);
alert($(this).css('background-color')); // alerts rgb(0, 0, 0)
if($(this).css('background-color') == 'rgb(255, 255, 255)' || 'rgba(0,0,0,0)'){
$(this).css('background-color', 'black');
alert(1);
var color = 'black';
} else{
alert(2);
$(this).css('background-color', 'white');
var color = 'white';
}
//alert(event.target.id);
update( event.target.id, color);
});
It is also reading everything great
function read(){
$.post("ajax.php",
{
read: '1',
},
function(data){
values=data.split('*');
//alert(values[1]);
var id = '#' + values[0]+ '';
//alert(id);
$( id ).css('background-color', values[1]);
}
);
}
I've added the HTML table but it is built with PHP and usually 25 by 25 but to make it easier I simplified it with a 5 by 5 representative
<table>
<tr>
<td style="height: 21px; width: 21px; background-color:white;" id="a1"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="a2"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="a3"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="a4"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="a5"></td>
</tr>
<tr>
<td style="height: 21px; width: 21px; background-color:white;" id="b1"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="b2"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="b3"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="b4"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="b5"></td>
</tr>
<tr>
<td style="height: 21px; width: 21px; background-color:white;" id="c1"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="c2"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="c3"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="c4"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="c5"></td>
</tr>
<tr>
<td style="height: 21px; width: 21px; background-color:white;" id="d1"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="d2"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="d3"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="d4"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="d5"></td>
</tr>
<tr>
<td style="height: 21px; width: 21px; background-color:white;" id="e1"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="e2"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="e3"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="e4"></td>
<td style="height: 21px; width: 21px; background-color:white;" id="e5"></td>
</tr>
</table>
If someone could help that would be amazing. Thank you