How to remove div element from css2d object

Hi I actually add the div element in css2d object in runtime and i also add the button and add listener with it. once I click that button then my remove functionality call and that div remove but once I do then it didn’t remove and existing in scene
let element=document.getElementById(;
here is my code of remove div element .the div which I created with css2d object and label renderer

Please use code blocks (three back ticks markdown syntax) for code, or press the code icon in the editor.

People are less likely to want to help people who paste unreadable code.

1 Like

You are right but my code inheritance is to much which I can’t upload to show you live .Can you please tell me is there any way which I can detect the css2d object with the help of click listener?

Btw, welcome. :slight_smile:

I see you tried to make a code block with quotes. You need back ticks. This symbol: `

Like this:

if (true) foo();

The result:

if (true) foo();

Or, select text and hit the code icon, this one:

Markdown syntax cheat sheet is here:

No need for this code. is exactly the same as document.getElementById(

So this code is the same as your code:

function(event) {

However, we have no idea what you’re trying to do. You’re gonna have to post more details.

I actually tried to click on css2d works but the thing is when I click and try to remove the element then it didn’t remove and see text label in the scene.I actually want to detect the label which i click

css2dObject.domElement.addEventListener('click', () => {


1 Like
let div = document.createElement( 'div' );
div.className = 'label';
div.textContent = '+';
div.type='button';'label6'; = '-1em';
let label = new CSS2DObject( div );
childModel.add( label );

scope_AC.modeler.labelRenderer.setSize( innerWidth, innerHeight ); = 'absolute'; = '15px'; = 'none'

Here is my code which i add text label in runtime

div.onclick = () => div.remove()


yes its not working

It isn’t clear what you are trying to do, and we’re not gonna be able to help unless you can provide a small working example reproduction or better code that shows exactly what the problem is.

Here is an example you can start from: