Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

194
Vistas
Why does the click event of JavaScript not working?

I got this link from a friend of mine for testing my reaction time. https://www.arealme.com/reaction-test/en/

This is a game where a red circle will appear and after random time it will turn green. I need to click as soon as it turns green. That is my reaction time.

With real reaction, my best score is 178, in case you don't believe I have attached ss enter image description here

I know I can edit this 178 to any number I want. But I wanted to create a script that generated the click event as soon as the green circle appears.

I have planned to call the below function with setInterval

const clickCircle = (className)=> {
    let greenCircles = document.getElementsByClassName(className);
    if(greenCircles && greenCircles.length){
        greenCircles[0].click();
    }else{
        console.log("No circles found with name ", className)
    }
}

clickCircle("tfny-circleGreen");

The name of the class containing the green circle is tfny-circleGreen. So calling clickCircle("tfny-circleGreen") should generate a click event. But it's not.

What am I missing?

Maybe they have overridden the click function. If that's the case, how do I restore it?

Please don't ask why I want this, it's just I wanted to try it this way for fun.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

function triggerMouseEvent (node, eventType) {
    var clickEvent = document.createEvent ('MouseEvents');
    clickEvent.initEvent (eventType, true, true);
    node.dispatchEvent (clickEvent);
}

const clickCircle = (className)=> {
    let greenCircles = document.getElementsByClassName(className);
    if(greenCircles && greenCircles.length){
        triggerMouseEvent (greenCircles[0], "mouseover");
        triggerMouseEvent (greenCircles[0], "mousedown");
        triggerMouseEvent (greenCircles[0], "mouseup");
        triggerMouseEvent(greenCircles[0], "click");
    }else{
        console.log("No circles found with name ", className)
    }
}

setInterval(()=> {
    clickCircle("tfny-circleGreen");
}, 10)

This is the complete code that works :D

The click() function was not working so I had to simulate it.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda