I'm having a table with tr generating in a loop
<table>
<div id="trresults">
{FOR LOOP}
<tr>
<td>sample text</td>
<td>sample text</td>
<td>sample text</td>
</tr>
<tr>
<td>sample text</td>
<td>sample text</td>
<td>sample text</td>
</tr>
{END FOR LOOP}
</div>
</table>
I want to group the tr's and set a id for that. So that I used div for that, but div will not work as in table all the items should be inside td's. So how can I solve this problem?
I'm having a table with tr generating in a loop
<table>
<div id="trresults">
{FOR LOOP}
<tr>
<td>sample text</td>
<td>sample text</td>
<td>sample text</td>
</tr>
<tr>
<td>sample text</td>
<td>sample text</td>
<td>sample text</td>
</tr>
{END FOR LOOP}
</div>
</table>
I want to group the tr's and set a id for that. So that I used div for that, but div will not work as in table all the items should be inside td's. So how can I solve this problem?
Share Improve this question edited May 25, 2019 at 13:56 halfer 20.4k19 gold badges109 silver badges202 bronze badges asked Jan 11, 2011 at 9:52 RajasekarRajasekar 19k35 gold badges109 silver badges140 bronze badges 6- 1 depending on what your goal is, maybe you can give all the tr's inside the loop the same class? – leeny Commented Jan 11, 2011 at 9:56
- I want id to be set not classes – Rajasekar Commented Jan 11, 2011 at 9:56
- Is there a reason you can't use multiple tables, and set the ID on each table? – Sam Dufel Commented Jan 11, 2011 at 9:59
- what code generates all the tr's? can the same code assign a unique id to each tr? please give us some details on the {FOR LOOP} part. – KBoek Commented Jan 11, 2011 at 10:00
- Hi Rajasekar, What is your reasoning for wanting an ID rather than class? – Alex KeySmith Commented Jan 11, 2011 at 10:04
1 Answer
Reset to default 6You can use a TBODY element to group your rows
<table>
<tbody id="trresults1">
{FOR LOOP}
<tr><td>for loop message</td></tr>
{END FOR LOOP}
</tbody>
<tbody id="trresults2">
{FOR LOOP}
<tr><td>for loop message</td></tr>
{END FOR LOOP}
</tbody>
</table>
Reference: Mozilla HTML Reference
<tbody>
<table>