HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Game</title>
<link rel="stylesheet" type="text/css" href="stylesheet.css">
<script src="script.js"></script>
</head>
<body>
<div class="container">
<table class="table ">
<tr>
<td id="1">a</td>
<td id="2">a</td>
<td id="3">a</td>
<td id="4">a</td>
</tr>
<tr>
<td id="5">a</td>
<td id="6">a</td>
<td id="7">a</td>
<td id="8">a</td>
</tr>
<tr>
<td id="9">a</td>
<td id="10">a</td>
<td id="11">a</td>
<td id="12">a</td>
</tr>
<tr>
<td id="13">a</td>
<td id="14">a</td>
<td id="15">a</td>
<td id="16">a</td>
</tr>
</table>
</div>
</body>
function startFunction() {
var table = document.querySelector('#table');
var table_cells = table.querySelectorAll('td');
}
window.onload = function() {
startFunction();
};
I keep getting an error of "uncaught typeError: cannot read property 'querySelectorAll' of null."
I think this has to do with the fact when I'm calling a function that tries to grab said element node before it exists perhaps?
I'm loading my Javascript file in the <head>
section of my HTML file so I added a window.onload
function to make sure everything is loaded before the page runs. However, I still keep getting this error.