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

201
Views
How can I add a string to an array when a checkbox is checked?

These are my strings and their speeds at which they will be displayed

var typed = new Typed(".auto-input", {
        strings: ["Hi, blahblahblah.", "blahblahblah...", "...blahblahblah?"],
        typeSpeed: 75,
        backSpeed: 75,
        loop: true
    });

This is my code for when my checkbox is checked

var checkbox = document.getElementById('checkbox');

checkbox.addEventListener('change', () => {
  document.body.classList.toggle('dark');
});

I tried an if statement

if (document.body.classList.toggle('dark')) {
  typed.push(["lorem"]);
}

But then i realized, i think i need to select the "strings" in my "typed" vaiable. I'm not quite sure how to do that. I apologize in advance for any mistakes, this is my first question posted on StackOverflow.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As you want to push "lorem" into strings inside Typed, your if statement should look like:

if (document.body.classList.toggle('dark')) {
  typed.strings.push("lorem");
}
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!