What is the solution for, cannot read property 'getcontext' of null canvas | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is the solution for, cannot read property 'getcontext' of null canvas

18th Mar 2019, 8:16 PM
Lweendela Kankoloto
Lweendela Kankoloto - avatar
2 Answers
+ 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. }
19th Mar 2019, 12:29 AM
Шащи Ранжан
Шащи Ранжан - avatar
+ 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>.
18th Mar 2019, 8:21 PM
Abdelkader settah
Abdelkader settah - avatar