0
canvas html
why canvas element must have id ?
2 Respuestas
+ 20
Not necessarily...
+ 4
Because that's the best way to refer to the element in your script. If you want to draw anything on the canvas, you need to do it with JavaScript. It doesn't absolutely need an ID, you could still find it by other means (DOM tree traversal), but it's the simplest and clearest method.
When you've given it the ID "theCanvas", for example, you can start editing it thusly:
var canvas = document.getElementById("theCanvas");