简体   繁体   中英

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM