0
What is the solution for, cannot read property 'getcontext' of null canvas
2 Antworten
+ 5
In addition to what Abdelkader said, and if not jQuery, write your entire JS inside a function which will be called once the html window gets loaded.
window.onload =function() {
//your JS code goes here.
}
+ 3
guess the problem is your js runs before the html is loaded.
If you are using jquery, you can use the document ready function to wrap your code:
$(function() {
var Grid = function(width, height) {
// codes...
}
});
Or simply put your JS after the <canvas>.