Note that there are some explanatory texts on larger screens.

plurals
  1. POMy JQuery Code for X O Game have some trouble with cheeking innerhtml?
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/9929868/i-want-to-check-if-td1-text-x">I want to check if $(&#39;#td1&#39;).text() === &ldquo;x&rdquo;?</a> </p> </blockquote> <p>My Jquery Code for X O Game have some trouble with cheeking innerhtml ? 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 .</p> <p>also I'm not sure if can do this with jQuery .</p> <pre><code>&lt;script type="text/javascript" &gt; 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(); } } &lt;/script&gt; &lt;BODY&gt; &lt;center&gt; &lt;h1 &gt;" X ,O Game "&lt;/h1&gt; &lt;table &gt; &lt;tr&gt; &lt;td id="td1" onclick="tdElm(1);" &gt;&lt;/td&gt; &lt;td id="td2" onclick="tdElm(2);"&gt;&lt;/td&gt; &lt;td id="td3" onclick="tdElm(3);"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="td4" onclick="tdElm(4);"&gt;&lt;/td&gt; &lt;td id="td5" onclick="tdElm(5);"&gt;&lt;/td&gt; &lt;td id="td6" onclick="tdElm(6);"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td id="td7" onclick="tdElm(7);"&gt;&lt;/td&gt; &lt;td id="td8" onclick="tdElm(8);"&gt;&lt;/td&gt; &lt;td id="td9" onclick="tdElm(9);"&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/center&gt; &lt;/BODY&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload