# Remove CSS2DObject not working

**URL:** <https://discourse.threejs.org/t/remove-css2dobject-not-working/40364>\
**Category:** Questions\
**Tags:** css2dobject\
**Created:** [July 15, 2022, 11:39am UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364 "2022-07-15T11:39:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gundeep\_Singh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gundeep_singh/32/25485_2.png) [@Gundeep\_Singh](https://discourse.threejs.org/u/Gundeep_Singh)\
**Post date:** [July 15, 2022, 11:39am UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364/1 "2022-07-15T11:39:50Z")

</div>

I need to remove all the CSS2DObject from my scene with below code it removes only first object then displays an error in traverse

```javascript
scene.traverse(function(child){
                 if(child instanceof CSS2DObject){
                     scene.remove(child);
                 }
             })

```

what is the proper way to remove all CSS2DObject from scene

---

<div class="post-metadata">

**Author:** ![Mugen87](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/mugen87/32/5645_2.png) [@Mugen87](https://discourse.threejs.org/u/Mugen87)\
**Post date:** [July 15, 2022, 11:41am UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364/2 "2022-07-15T11:41:52Z")

</div>

Duplicate of [Cannot read property 'traverse' of undefined when traverse object in scene and remove it](https://discourse.threejs.org/t/cannot-read-property-traverse-of-undefined-when-traverse-object-in-scene-and-remove-it/28672)

---

<div class="post-metadata">

**Author:** ![Gundeep\_Singh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gundeep_singh/32/25485_2.png) [@Gundeep\_Singh](https://discourse.threejs.org/u/Gundeep_Singh)\
**Post date:** [July 15, 2022, 11:56am UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364/3 "2022-07-15T11:56:09Z")

</div>

```javascript
scene.children.forEach(function(){
                console.log(scene.children);
                
                if(scene.children instanceof CSS2DObject){
                    scene.remove(scene.children);
                }
            })

```

I tried this code also but didn’t work is this right way?

---

<div class="post-metadata">

**Author:** ![anidivr](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/anidivr/32/32924_2.png) [@anidivr](https://discourse.threejs.org/u/anidivr)\
**Post date:** [July 15, 2022, 12:01pm UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364/4 "2022-07-15T12:01:27Z")

</div>

Try making an array of objects to remove, then do the removing outside of the scene object

const toremove = [];  
scene.traverse(function(child){  
if(child instanceof CSS2DObject){  
toremove.push(child)  
}  
});  
toremove.forEach(child =\> scene.remove(child));

---

<div class="post-metadata">

**Author:** ![Gundeep\_Singh](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/gundeep_singh/32/25485_2.png) [@Gundeep\_Singh](https://discourse.threejs.org/u/Gundeep_Singh)\
**Post date:** [July 15, 2022, 12:05pm UTC](https://discourse.threejs.org/t/remove-css2dobject-not-working/40364/5 "2022-07-15T12:05:43Z")

</div>

Thanks buddy for help
