Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
49
rated 0 times [  51] [ 2]  / answers: 1 / hits: 106015  / 14 Years ago, thu, may 27, 2010, 12:00:00

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');

More From » jquery

 Answers
253

Try:



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


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


[#96656] Wednesday, May 26, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
jameson

Total Points: 534
Total Questions: 103
Total Answers: 102

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
jameson questions
;