I have the following working code:
ctx = document.getElementById(\"canvas\").getContext(\'2d\');
Is there any way to re-write it to use
try{
ctx = $('#canvas').get(0).getContext('2d');
}catch(e){
console.log('We have encountered an error: ' + e);
}
or...
if( typeof $('#canvas') === 'undefined'){
var canvas = '
Using setTimeout is an easy way to ensure you don't try calling the canvas element before it's fully created and registered to the DOM.