Issue in add listener

Hi can you plzz tell me what i am doing wrong in this line

let div = document.createElement( 'div' );
div.className = 'label';
div.textContent = '+';
div.type='button';
div.id='label6';
div.onclick=addEventListener("click",function);

function not call once I press

Try
div.addEventListener("click",function);

1 Like

nope its not working

div.addEventListener(“click”,otherscript.function); i actually do this but nothing happened

Only you know your scene setup, and what and how works there :thinking:

div.addEventListener(“click”,otherscript.function);
I just add the event listener on button and its a css2drenderer.So when i click this it didnt show me anything .Is there anyway to handle this?

Does otherscript.function work, if you call it not in the event listener?
Does it show something in the console if you do div.addEventListener(“click”, event => {console.log("event fired")});?
Any chance to provide a minimal live code working example that demonstrates the issue (codepen, codesandbox etc.)? Not specifically for me, but for the others, who would like to help.

your line didnt work .Yes otherscript.function works when you call without event listener

Here Globe with markers and label: thoughts, ideas, approaches, solutions I used pointerdown event for [X]-button on the label.

i got the solution
labelRenderer.domElement.style.pointerEvents = ‘none’.i added this line

but once i add the marker then my scene stuck and orbit control not working

Then it’s not the solution.
In the demo provided above, I successfully use OrbitControls with CSS2DRenderer and mouse interaction.

You are right but can you please tell why its not working with webgl renderer I’m actually add the label renderer in orbitcontrol .When I load the screen then orbit control doesn’t work but once i click on model then label apply and addlistener and orbit control works. This issue I’m facing

Once again:

Without a minimal example, all we can do is to shoot at random, trying to choose what’s wrong and wasting the time.

Sorry for the late response you are right but the interitance of the scripts is soo much to show in live.

let div = document.createElement( ‘div’ );
div.className = ‘label’;
div.textContent = ‘+’;
div.type=‘button’;
div.id=‘label6’;
div.style.marginTop = ‘-1em’;
div.addEventListener(“mousedown”,scope_AC.uiHandler.addConnectionBtns,false);
let label = new CSS2DObject( div );
label.position.copy(pos);
childModel.add( label );

scope_AC.modeler.labelRenderer.setSize( innerWidth, innerHeight );
scope_AC.modeler.labelRenderer.domElement.style.position = ‘absolute’;
scope_AC.modeler.labelRenderer.domElement.style.top = ‘15px’;
scope_AC.modeler.labelRenderer.domElement.style.pointerEvents = ‘none’
document.body.appendChild(scope_AC.modeler.labelRenderer.domElement );

can you please explain why label renderer button and html button is not working in same scene.