+ 1
Why this code is showing getContext () is error
It is showing cannot read getContext () of null . https://code.sololearn.com/W6mrXACbXQi9/?ref=app
6 Réponses
+ 3
https://www.sololearn.com/post/90825/?ref=app
+ 3
On sololearn, code written in javascript tab runs before the code in HTML tab.
As a result JS tries to access HTML DOM before it exists. As DOM is not ready `document.querySelctor` returns `null`.
You can try this solution,
Wrap code within a callback function to `load` event as below :
window.addEventListener('load',function(){
//code here.
});
Or, assign a function to `window.onload` property:
window.onload=function(){
//code here
};
There is also third way. Write in script tag below body tag
.
.
.
</body>
<script>
//code here
</script>
.
.
.
But I'll suggest don't use this last method.You'll not get code highlighting. First method is best.
+ 2
🎶💞Sravs💞🥀 , Have you read the post that I linked in previous answer?
+ 1
Could you explain clearly, where I have did mistake..
0
Yes,but I am confusing
0
Tq