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

177
Vistas
how to run JS code when button is clicked

Is it possible to amend the below code so that when you click on a button with the ID #slide-1-next , the javascript code runs? Ideally the code would not run until the button has been clicked. Im not super well versed in JS but I think maybe the last line of code with the event listener can be amended to achieve this?

let text = 'What follows is Lorem ipsum translated to English: But I must explain to you how all this mistaken idea of reprobating pleasure and extolling pain arose.';

function type() {
    let textChar = text.charAt(textLength++);
    let paragraph = document.getElementById("typed");
    let charElement = document.createTextNode(textChar);
    paragraph.appendChild(charElement);
    if(textLength < text.length+1) {
        setTimeout('type()', 50);
    } else {
        text = '';
    }
}
  
document.addEventListener("DOMContentLoaded", function() {
    type();
  });
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

To summarize the comments above, adding the following line at the end of your code block will run the type function when the button with ID slide-1-next is clicked:

document.getElementById("slide-1-next").onclick = type;
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