Im getting this error:
Uncaught TypeError: Cannot read property 'getContext' of null
in my demo.js page
I have included demo.js page in my html page (start page) .
How can i solve this error?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Laxmidhar SahooPosted May 4, 2019, 4:09 AM
Manoj BhoirPosted May 4, 2019, 3:52 AM
I 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:
Bryian TanPosted May 3, 2019, 3:27 PM
Afzaal Ahmad ZeeshanPosted May 3, 2019, 2:45 PM
My guess is that you are trying to use the HTML5 canvas element to render something on top of it, in that case the variable that is holding the reference of your canvas is null. Make sure that the canvas element (or whatever element that has this getContext() function) exists in the DOM.