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

486
Vistas
Why button.click() is not working in my script?

I have a script in JavaScript that in a part of the code create a 'virtual button' and press it automatically.

This button is not in the HTML page and is only used to store a link that at a certain point of the script must be clicked. Here's the code:

var virtualButton = document.createElement("button");
var linkText = document.createTextNode("assign to relevant user");
virtualButton.appendChild(linkText);
virtualButton.title = "assign to relevant user";
virtualButton.href = link;
document.body.appendChild(virtualButton);

virtualButton.click();

Everything seems fine to me, still the code does not actually click the button.

Am I missing something here?

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

0

<button/> elements do not have an .href attribute. You most likely want to use an anchor (<a/>) element. See below:

var virtualButton = document.createElement("a");
var linkText = document.createTextNode("assign to relevant user");
virtualButton.appendChild(linkText);
virtualButton.title = "assign to relevant user";
virtualButton.href = "https://www.google.com";
document.body.appendChild(virtualButton);

virtualButton.click();

(It won't actually navigate because it is in a sandboxed <iframe/>, but you will see it attempt to do so).

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