I want to check if $('#td1').text() === "x"?
Posted
by
M.z
on Stack Overflow
See other posts from Stack Overflow
or by M.z
Published on 2012-03-29T16:52:58Z
Indexed on
2012/03/29
17:29 UTC
Read the original article
Hit count: 115
JavaScript
|jQuery
I want to check if innerHtml have X or O , so i can not add again any thing else , but it's not working . it stop after adding the check code , I'm trying here to do a simple X O game to get more familiar with javascript and jquery .
also I'm not sure if can do this with jQuery .
<script type="text/javascript" >
function ranFun() {
return Math.floor((Math.random() * 9) + 1);
}
var a;
function Elment(a) {
document.getElementById("td" + a).innerHTML = "O";
}
function call() {
var x = ranFun();
switch (x) {
case 1:case 2 :case 3: case 4 :case 5 : case 6 : case 7 : case 8 : case 9 :
Elment(x);
break;
default:
break;
}
}
function tdElm(c) {
if ($('#td1').text() === "x" || $('#td1').text() == "o")
return false;
else {
document.getElementById("td" + c).innerHTML = "x";
call();
}
}
</script>
<BODY>
<center>
<h1 >" X ,O Game "</h1>
<table >
<tr>
<td id="td1" onclick="tdElm(1);" ></td>
<td id="td2" onclick="tdElm(2);"></td>
<td id="td3" onclick="tdElm(3);"></td>
</tr>
<tr>
<td id="td4" onclick="tdElm(4);"></td>
<td id="td5" onclick="tdElm(5);"></td>
<td id="td6" onclick="tdElm(6);"></td>
</tr>
<tr>
<td id="td7" onclick="tdElm(7);"></td>
<td id="td8" onclick="tdElm(8);"></td>
<td id="td9" onclick="tdElm(9);"></td>
</tr>
</table>
</center>
</BODY>
© Stack Overflow or respective owner