CyanPrime
CyanPrime

Reputation: 5193

Why doesn't this Canvas show up?

Can anyone tell me why this canvas won't show up? I just don't get it, it doesn't even display the

tag. I'm on crunchbang 10 using chromium. All other canvases work, but this one doesn't.

<!doctype html>  
<html lang="en">  
    <head>  
          <meta charset="utf-8">  
          <title>Test</title>  
          <meta name="description" content="An HTML5 Test">  
          <meta name="author" content="William Starkovich">  
          <link rel="stylesheet" href="css/styles.css?v=1.0">
          <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
            $(document).ready(function(){

                //get a reference to the canvas
                var ctx = $('#canvas')[0].getContext("2d");

                //draw a circle
                ctx.beginPath();
                ctx.arc(75, 75, 10, 0, Math.PI*2, true); 
                ctx.closePath();
                ctx.fill();
            }
          </script>    
    </head>  
    <body>  
         <canvas id="canvas" width="800px" height="100px">
        <p>Your browser doesn't support canvas.</p>
        </canvas>
    </body>  
</html> 

Upvotes: 2

Views: 460

Answers (2)

JaredPar
JaredPar

Reputation: 754715

The problem is a syntax error in your JavaScript code. You're missing a ); on the closing } of the main function

  $(document).ready(function(){

            //get a reference to the canvas
            var ctx = $('#canvas')[0].getContext("2d");

            //draw a circle
            ctx.beginPath();
            ctx.arc(75, 75, 10, 0, Math.PI*2, true); 
            ctx.closePath();
            ctx.fill();
  });

Upvotes: 3

Simon Sarris
Simon Sarris

Reputation: 63812

There's an error in your JavaScript syntax:

        }) // you are missing this parenthesis
      </script>  

Other than that the canvas absolutely shows up. Add:

<canvas id="canvas" width="800px" height="100px" style="border: 1px solid black">

To see a border around it.

Example:

http://jsfiddle.net/RmVs4/8/

Upvotes: 2

Related Questions