I use domElement to append the data in window. But how can I use html div tag to append it to the window?
I got the error
Cannot read property 'appendChild' of null
where I can't append my three js code in div element.
 <html>
<head>
    <title>
        Ajay's Beginners guide
    </title>
</head>
<body>
    <script src="../build/three.js"></script>
    <script>
        var scene, camera, renderer;
        function init() {
            var scene = new THREE.Scene();
            var WIDTH = window.innerWidth,
                HEIGHT = window.innerHeight;
        }
        renderer = new THREE.WebGLRenderer();
        // renderer.setSize(WIDTH, HEIGHT);
        console.log(document.body);
        canvas = document.getElementById('mycanvas');
        canvas.appendChild(renderer.domElement);
        renderer.setClearColorHex(0x333F47, 1);
        //color and opacity
        var light = new THREE.PointLight(0xffffff);
        light.position.set(-100, 200, 100);
        scene.add(light);
        camera = new THREE.PerspectiveCamera(45, WIDTH / HEIGHT, 0.1, 2000);
        camera.set.position(0, 6, 0);
        scene.add(camera);
        var loader = new THREE.JSONLoader();
        loader.load("models/treehouse_logo.js", function (geometry) {
            var material = new THREE.MeshLambertMaterial({ color: ox55B663 });
            mesh = new THREE.Mesh(geometry, material);
            scene.add(mesh);
        });
        controls = new THREE.OrbitControls(camera, render.domElement);
        window.addEventListener('resize', function () {
            var WIDTH = window.innerWidth;
            var HEIGHT = window.innerHeight;
            renderer.setSize(WIDTH, HEIGHT);
            camera.aspect = WIDTH / HEIGHT;
            camera.updateProjectionMatrix();
        });
        // init();
        function animate() {
            requestAnimationFrame();
            renderer.render(scene, camera);
            controls.update();
        }
    </script>
    <div id="mycanvas">
    </div>
</body>
</html>
 
    