Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

176
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!