Get Reference to Canvas using jQuery

Get Reference to Canvas using jQuery

You can use JavaScript to get reference to a canvas in HTML5 but if you are someone so much into jQuery then you can use the following method to get reference to canvas using jQuery.

Old School Way

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

jQuery Way

var canvas = $("#myCanvas");
var context = canvas.get(0).getContext("2d");
Did you enjoy this article?
Signup today and receive free updates straight in your inbox. We will never share or sell your email address.

Leave a Reply