This code works:
<canvas id="myCanvas" width="578" height="200"></canvas>
<script>
var canvas = document.getElementById('myCanvas');
var context = canvas.getContext('2d');
context.beginPath();
context.moveTo(0, 200);
context.lineTo(578, 0);
context.stroke();
context.beginPath();
context.moveTo(0, 0);
context.lineTo(578, 200);
context.stroke();
</script>
I tried to do the same in jQuery and that did not work:
“Object [object Object] has no method ‘getContext’“
var context = $('.dropzone').getContext('2d');
context.beginPath();
context.moveTo(0, 200);
context.lineTo(578, 0);
context.stroke();
context.beginPath();
context.moveTo(0, 0);
context.lineTo(578, 200);
context.stroke();
I even read on stackoverflow that I should try this (that did not work)
Added a [0] to the code.
“Object #<HTMLDivElement> has no method ‘getContext’“
var context = $('.dropzone')[0].getContext('2d');
Question
I want to “paint” in every .dropzone. Is that not possible? How?
Use
.each()Here’s an example on jsfiddle.