user2910074 user2910074 - 12 days ago 8
HTML Question

How can I quickly give 625 cells an ID?

I'm trying to create a table with 25 rows and 25 columns. I need each

<td>
to be assigned a unique ID. To do this manually, I would have to write the id of each
<td>
625 times, which is a monotonous task. How can I do this quickly and easily?

I was thinking that I could give each
<tr>
an ID which is a value between 1 and 25. The ID of each
<td>
could then perhaps be given by

*ID of corresponding tr* + "- i"


For integers 0

Answer

Yes, your mind is going in the right direction. You could use Javascript or let the html be generated by Razor with an .cshtml and C# in it ... Maybe its easier if you generatre the whole table with JS and do not write the table in pure html and try to modify at later. If you dont want to depend on activated JS you could juse JS to generate the code once and then copy the pure html.

Use some kind of loop and repeat to append some html code via JS

<html>
<table>
<tbody id="myTable">
</tbody>
</table>

<script type="text/javascript">
var i = 0;
while(i < 100)
{
document.getElementById('myTable').innerHTML += "<tr id='" + i + "'>Hallo</tr>";
i++;
}
</script>
</html>