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

207
Vistas
Append code to function of onclick of button

I have this button <button id='a'></button> which I trigger its click by js document.getElementById('a').onclick=function(){alert('Hello world');}. How to append code to this function inside the tag like this <button id='a' onclick='this.onclick; alert('hello 2');'></button>

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

0

You can call addEventListener to add more click listeners in addition to the onclick handler originally assigned in the HTML. Done this way, both handlers will execute when you click the button.

document.getElementById('a').addEventListener('click', function() {
  alert('2');
});
<button id="a" onclick="alert('1')">Test</button>

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