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

215
Vistas
how can i alternate row class after api data

I have tried everything i know and can't get an alterate tablerow class to work , without having all the rows duplicated or having a bunch of dummy rows inserted

Here is what i have

<script>
fetch("https://www63.myfantasyleague.com/2021/export?TYPE=league&L=43570&JSON=1").then(
  res => {
    res.json().then(
      data => {
        console.log(data.league.franchises.franchise);
        if (data.league.franchises.franchise.length > 0) {
          var temp = "";
          temp += "<table id='league_emails'>";
          temp += "<tbody>";
          temp += "<tr><th>Franchise</th><th>Owner Name</th><th>Email</th></tr>";
          data.league.franchises.franchise.forEach((itemData) => {

            for (var i = 0; i < data.league.franchises.franchise.length; i++) {
              if (i % 2)
                temp += '<tr class="eventablerow">';
              else
                temp += '<tr class="oddtablerow">';

            }

            temp += "<td>" + itemData.name + "</td>";
            temp += "<td>" + itemData.owner_name + "</td>";
            temp += "<td>" + itemData.email + "</td>";

          });
          temp += "</tbody>";
          temp += "</table>";
          document.getElementsByClassName('commish_league_safe')[0].innerHTML = temp;
        }
      }
    )
  }
)
</script>
<div class="commish_league_safe"></div>

The issue lays here and i have tried a dozen things and wrapped it different ways

for (var i = 0; i < data.league.franchises.franchise.length; i++) {
    if (i % 2)
        temp += '<tr class="eventablerow">';
    else
        temp += '<tr class="oddtablerow">';

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

0

<script>
fetch(https://www63.myfantasyleague.com/2021/export?TYPE=league&L=43570&JSON=1).then(
  res => {
    res.json().then(
      data => {
        console.log(data.league.franchises.franchise);
        if (data.league.franchises.franchise.length > 0) {
          var temp = "";
          temp += "<table id='league_emails'>";
          temp += "<tbody>";
          temp += "<tr><th>Franchise</th><th>Owner Name</th><th>Email</th></tr>";
          data.league.franchises.franchise.forEach((itemData,i) => {

            /* for (var i = 0; i < data.league.franchises.franchise.length; i++) { */
              if (i % 2)
                temp += '<tr class="eventablerow">';
              else
                temp += '<tr class="oddtablerow">';

            /* } */

            temp += "<td>" + itemData.name + "</td>";
            temp += "<td>" + itemData.owner_name + "</td>";
            temp += "<td>" + itemData.email + "</td>";
            temp += "</tr>";

          });
          temp += "</tbody>";
          temp += "</table>";
          document.getElementsByClassName('commish_league_safe')[0].innerHTML = temp;
        }
      }
    )
  }
)
</script>
<div class="commish_league_safe"></div>

Just before ending the loop close the tr tag. temp += "" + itemData.email + ""; after this line just add closing tag to append that to temp variable.

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