0

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>

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.