Noah
Noah

Reputation: 445

I have a canvas inside the div. How do I get it?

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>Girl! Fly and eat the yogurt!</title>
    <script src="js/easeljs-0.8.1.min.js"></script>
    <script src="js/sketch.js"></script>
    <script src="jquery-1.11.3.min"></script>
    <link rel="stylesheet" href="css/particles.css">
    <style type="text/css">
        #frame {
            position: relative;
            text-align: center;
            margin-top: 100px;
        }
    </style>
</head>
<body>
    <div id = "frame">
        <canvas class=" sketch" height="385" width="1440"></canvas>
    </div>
    <script src="js/particles.js"></script>
    <script>
        var canvas = $("#frame").get(0);
        canvas.id = "gameView";
    </script>
    <script src="js/app.js"></script>
</body>
</html>

Would you please tell me how to get the canvas inside the div using either jQuery or vanilla JS in this specific case? And how to set an id for the captured canvas element?

Upvotes: 4

Views: 8223

Answers (1)

Mike Cluck
Mike Cluck

Reputation: 32511

var canvas = document.querySelector('canvas');

Upvotes: 7

Related Questions