I have an html table with many rows. I'm currently grouping several rows inside a div (I know this is ugly) and then show or hide the divs to show or hide the rows inside it. Is there a standard way to do this. Something like rowgroup or multiple tbody instead of this ugly div grouping?
Asked
Active
Viewed 3.0k times
53
-
Ray's answer is correct. I'm surprised you haven't tried it yet, since you mention it in your question. – Robusto Mar 18 '10 at 13:28
2 Answers
100
Use <tbody>
tags for this

Ray
- 21,485
- 5
- 48
- 64
-
2Can you have multiple tbodys to group the rows. I've though that you had one thead, one tbody, and one tfoot per table. – Ricardo Marimon Mar 19 '10 at 02:32
-
17Multiple tbdodys are fine. You are correct that only one thead and tfoot are allowed. – Ray Mar 19 '10 at 11:26
-
3`` tags do not support everything that other tags do such as padding and margin, for these situations, @matpol has the better solution, but this is the best solution to the question from the OP unless under these special circumstances. – amaster Aug 21 '13 at 19:59
-
Beware of automatic `tbody` addition http://stackoverflow.com/questions/938083/why-do-browsers-insert-tbody-element-into-table-elements and add all those `tbody` elements explicitly on the HTML. – Ciro Santilli OurBigBook.com Jul 20 '14 at 11:45
-
what about nested tbody for the purpose of grouping rows above a tbody and those within? – Mike de Klerk Dec 17 '15 at 14:25
8
Give them a class name that is consistent then you can do:
$('table td.classname')
To get the ones you want.

matpol
- 3,042
- 1
- 15
- 18
-
In the old days retrieving elements by class name could be unacceptably slow on some browsers. Today it's usually built into the DOM. – Tomasz Gandor Sep 01 '13 at 13:29
-
3