-2

I try to make a table in HTML and want to boost it with jQuery .

The table is static and I wish firstly to the first column I call " Index " generate an index list with a for loop. For a visual like this:

Indice | champs 1 | champs 2 | champs 3 |

 1

 2

 3

 4
 ...

My table has identifier id ="balance", and the rest of the fields of the table I want to generate after .

Code I tried:

for (i = 1; i <= 8; i++) {
  $('.bilan td:first-child').append("<td><strong>" + i + "</strong></td>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="bilan" cellspacing="0">
  <tr>
    <td><strong>Indice</strong></td>
    <td><strong>Comptoir</strong></td>
    <td><strong>Nb commandes</strong></td>
    <td><strong>CA (&#x20ac;)</strong></td>
    <td><strong>% CA</strong></td>
    <td><strong>Nouveaux clients</strong></td>
  </tr>
</table>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
k. oth
  • 33
  • 6

1 Answers1

0

Perhaps you mean

for (i = 1; i <= 8; i++) {
  $(".bilan").append("<tr><td><strong>" + i + "</strong></td></tr>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="bilan" cellspacing="0">
  <tr>
    <td><strong>Indice</strong></td>
    <td><strong>Comptoir</strong></td>
    <td><strong>Nb commandes</strong></td>
    <td><strong>CA (&#x20ac;)</strong></td>
    <td><strong>% CA</strong></td>
    <td><strong>Nouveaux clients</strong></td>
  </tr>
</table>

Or better.

for (i = 1; i <= 8; i++) {
  $(".bilan tbody").append("<tr><td><strong>" + i + "</strong></td></tr>");
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table class="bilan" cellspacing="0">
  <thead>
    <tr>
      <th>Indice</th>
      <th>Comptoir</th>
      <th>Nb commandes</th>
      <th>CA (&#x20ac;)</th>
      <th>% CA</th>
      <th>Nouveaux clients</th>
    </tr>
  </thead>
  <tbody></tbody>
</table>
mplungjan
  • 169,008
  • 28
  • 173
  • 236