Note that there are some explanatory texts on larger screens.

plurals
  1. POUndefined HTML Element
    primarykey
    data
    text
    <p>I've made a <a href="http://en.wikipedia.org/wiki/Knight%27s_tour" rel="nofollow noreferrer">Knight's Tour</a> game in javascript. You can try it <a href="http://agweber.net/games/chess/knights.html" rel="nofollow noreferrer">here</a>. <em>(Particularly for reproducing the error)</em></p> <p>The error I'm having so much trouble finding reads</p> <blockquote> <p>Uncaught TypeError: Cannot read property 'innerHTML' of undefined</p> </blockquote> <p>but I'm not sure why it's undefined. I have a table with 64 cells (making a chessboard). They're all built as plain and empty</p> <pre><code>&lt;table border=1 style="border: 1px solid black; table-layout: fixed;"&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt;&lt;td&gt;&lt;/td&gt; &lt;/tr&gt;&lt;tr&gt; ... </code></pre> <p>This is the only table on the page. I use javascript to retrieve all of the td elements and I iterate through them adding ids, classes, background color and onclick eventListeners for gameplay.</p> <pre><code>var tds; window.onload = function() { tds = document.getElementsByTagName("td"); for (var i = 0; i &lt; tds.length; i++) { if (typeof window.addEventListener === 'function') { (function (td) { ... td.addEventListener('click', function() { ... </code></pre> <p>There seems to be a few different cells that repeatably have this error occur. Sometimes I can get the individual cell to produce an error, other times I can't. One repeatable example is to move first on the bottom row, second to last cell, and then try to move onto the cell two up and one right from it along the side.</p> <p>I read the innerHTML attribute frequently inside the onclick. I refer to the global tds array of td elements. Here are basically all forms of myself accessing them.</p> <pre><code>if (tds[cell].innerHTML === "") { if (tds[n].innerHTML === "♞") { tds[cell].innerHTML = "♞"; tds[target].innerHTML = "♘"; td.innerHTML = "♞"; </code></pre> <p>I really thought I had it figured out when I was <a href="https://stackoverflow.com/questions/1470488/difference-between-using-var-and-not-using-var-in-javascript">reading about</a> the difference between declaring a variable using var and when not using it, but I couldn't figure out a single var that was causing this error. Any help would be appreciated.</p>
    singulars
    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