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

150
Views
eliminar parte del texto en un div usando javacript

Me gustaría eliminar parte (4 primeros caracteres) de un texto en una lista de etiquetas de intervalo (filtradas por el nombre de la clase):

 <span class="time">00:00:50</span> <span class="time">00:01:22</span> <span class="time">00:02:44</span>

Me gustaría conseguir esto:

 <span class="time">0:50</span> <span class="time">1:22</span> <span class="time">2:44</span>

Intento algunos códigos usando text.substr(1, 4) pero ninguno de ellos funciona.
¿Alguien podría ayudarme?

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

0

Puedes usar una expresión regular para que coincida

 document.querySelectorAll(".time").forEach(function (elem) { elem.textContent = elem.textContent.match(/[1-9]?\d:\d\d$/)[0]; });
 <span class="time">00:00:50</span> <span class="time">00:01:22</span> <span class="time">00:02:44</span>

substr si siempre será X:XX

 document.querySelectorAll(".time").forEach(function (elem) { elem.textContent = elem.textContent.substr(-5); });
 <span class="time">00:00:50</span> <span class="time">00:01:22</span> <span class="time">00:02:44</span>

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!