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

128
Vistas
assigning index number to row in table

I want to add an index number to each row in a table automatically, like the one in the screenshot that I got from bootstrap's site here, I have tried multiple solutions but kept getting an index of -1 for all the rows, I would really appreciate the help, thank.

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

0

Does this work for you?

// tbl is the table
var rows = tbl.rows; n = 1;
for (i=0; i<rows.length; i++) {
  row = rows[i];
  f = row.firstElementChild;
  if (f) {
    el = document.createElement(f.tagName);
    el.innerHTML = (f.tagName == "TH") ? "#" : n;
    row.insertBefore(el, f);
    if (f.tagName != "TH") n++;
  }
}
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