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

147
Vistas
remove part of text in a div using javacript

I would like to remove part (4 first characters) of a text in a list of span tags (filtered by the class name):

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

I would like to get this:

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

I try some codes using text.substr(1, 4) but none of them works.
Could someone help me?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use a regular expression to match it

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 if it will always be 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 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