Jake
Jake

Reputation: 57

JavaScript and HTML5 canvas (basic) issue

I am trying to learn how to use a canvas and i cannot for the life of me figure out why this basic code wont work does anyone know what I am doing incorrect?

jsfiddle

<canvas id="ctx" width="500" height="500" style="border:1px solid #000000"></canvas>
 <script >

 var canvas = document.getElementById("canvas");
 var ctx = canvas.getContext("2d");

 ctx.fillText = ("hey", 50, 50);

 </script>

Upvotes: 0

Views: 49

Answers (1)

Sam Parmenter
Sam Parmenter

Reputation: 1841

You are passing the wrong ID to getElementById. Your canvas id is ctx not canvas. Use document.getElementById('ctx').

Upvotes: 1

Related Questions