+ 2
Canvas question?
When you play around with the examples in a lesson, it works fine. But if try your own it doesn't work. for eg. var c = document.getElementById("canvas"); var ctx=c.getContext("2d"); always results in: cannot read property 'getContext' of null line blahblah Why does this happen?
10 ответов
+ 7
If you wrote the code in the JS tab, you need to wrap it inside window.onload so that the document is loaded first before the script.
window.onload = function(){
var c=document.getElementById("canvas1");
var ctx=c.getContext("2d");
}
+ 7
should really make a post explaining this issue and how to handle it (with pics)
just too lazy ._.
+ 6
just added a (long long long) post regarding this issue
https://www.sololearn.com/post/7444/?ref=app
can also refer to it any other users who encounter this
+ 4
Smithy , it's actually a common problem for beginners here on Sololearn.
I also struggled about that issue before.😅
+ 2
Good luck👍
+ 1
Thank you Jonathan Pizarra I will try that
+ 1
Jonathan Pizarra glad I'm not the only one. Your solution works fine, now to try some of the other ones they mentioned. I still trying to get a circle to work, but not giving up on it yet😊
+ 1
Jonathan Pizarra Thanks mate
+ 1
Burey Thank you
0
Burey it could be handy, or maybe I'm the only one having trouble with it 😂😂😂