views:

120

answers:

2

I have the following working code:

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

Is there any way to re-write it to use $? Doing this fails:

ctx = $("#canvas").getContext('2d');
+5  A: 

Try:

$("#canvas")[0].getContext('2d');

jQuery exposes the actual DOM element in numeric indexes, where you can perform normal JavaScript/DOM functions.

Matt
+1  A: 
$("#canvas")[0].getContext('2d');
Andy E