In this code :
var canvas = $("#myCanvas")[0];
var ctx = canvas.getContext("2d");
Why do we have to add [0]
to identify the canvas? It's a bit confusing for me, because [n]
is usually added when there are multiple elements with the same name and we need to address a particular one. But an id can only refer to one unique element.