I'm just starting out working with the HTML5 canvas and I want to use onclick to call as js function in my document.
However, despite declaring the function in my JS, I still get [function name] is not defined when clicking.
The function is defined as such:
function draw_b() {
var b_canvas = document.getElementById("b"); // finds the canvas in the DOM
var b_context = b_canvas.getContext("2d"); // context for drawing. No 3D option yet
b_context.fillRect(50, 25, 150, 100);
}
The click event is included as such:
onclick="draw_b();return false"
Yet when I click the element, I get:
draw_b is not defined
No Wrap - In Headin jsFiddle. Also what isdocument.getElementById("b"), where is it defined? Maybe you meana?