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

238
Views
clearInterval en bucle no funciona como se esperaba

tengo un problema cuando borro las letras me queda la palabra

tengo dos h1 borro la palabra de cada h1 y cuando se borran todas las letras detengo el intervalo para cada h1 especialmente para ella

imagen

 let mySelector = document.querySelectorAll(".writ-text"); for (let l = 0; l < mySelector.length; l++) { removeText = setInterval(function() { // Cut the last letter of the word and print the word after editing document.querySelectorAll(".writ-text")[l].textContent = document.querySelectorAll(".writ-text")[l].textContent.substr(0, document.querySelectorAll(".writ-text")[l].textContent.length - 1); // Check if the entire word has been deleted if (document.querySelectorAll(".writ-text")[l].textContent.length == 0) { clearInterval(removeText) } }, 1000); }
 <h1 class="writ-text">gold</h1> <h1 class="writ-text">golder</h1>

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

0

Ha borrado el único setInterval llamado removeText (ámbito global) que lo hace para ambos textos.
Use un alcance de bloque como let const para hacer ejercicio

 let mySelector = document.querySelectorAll(".writ-text"); for (let l = 0; l < mySelector.length; l++) { let removeText = setInterval(function() { // Cut the last letter of the word and print the word after editing document.querySelectorAll(".writ-text")[l].textContent = document.querySelectorAll(".writ-text")[l].textContent.substr(0, document.querySelectorAll(".writ-text")[l].textContent.length - 1); // Check if the entire word has been deleted if (document.querySelectorAll(".writ-text")[l].textContent.length == 0) { clearInterval(removeText) } }, 1000); }
 <h1 class="writ-text">gold</h1> <h1 class="writ-text">golder</h1>

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!