0

Uncaught type error; cannot read properties of getContext JAVASCRIPT

I wrote Var canvas = document.getElementById('canvas') Var context = canvas.getContext("2d") But it gets an error help pls I made a canvas in html with a black border and I wanna fill it ;-; thanks in advance

8th Mar 2022, 5:06 AM
Rafin
Rafin - avatar
3 Respostas
+ 3
Try to put canvas before style, but it's best to write styles in CSS
8th Mar 2022, 9:06 AM
Solo
Solo - avatar
+ 4
Show your code. Have you given your canvas an id with the same name?
8th Mar 2022, 5:23 AM
Solo
Solo - avatar
+ 1
Solo html code <!DOCTYPE html> <html> <head> <title>Page Title</title> </head> <body> <style> #canvas { width:150px; height:150px; border:2px solid black; } </style> <canvas id="canvas"></canvas> </body> </html>
8th Mar 2022, 8:02 AM
Rafin
Rafin - avatar