javascript - Uncaught TypeError: Cannot read property 'getContext' of null Help Please -


i keep getting error in title. doing wrong? dont want use jquery. know there simple answer this, im literally not seeing it.

<!doctype html> <html> <body> <canvas id="canvas1" width="500px" height="500px"> </canvas>  <script>     var canvas = document.getelementbyid("#canvas1");     var c = canvas.getcontext("2d");      c.beginpath();     c.moveto(0,0);     c.lineto(100,100);     c.stroke(); </script> </body> </html> 

you done minor mistake @ following line

 var canvas = document.getelementbyid("#canvas1"); 

instaed specify id without # like

  var canvas = document.getelementbyid("canvas1"); 

Comments

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

Making Empty C++ Project: General exception (Exception from HRESULT:0x80131500) Visual Studio Community 2015 -

How to fix java warning for "The value of the local variable is not used " -