Reputation: 896
How do I wrap the table's tbody with a div?
myTable:
<table>
<thead></thead>
<tbody></tbody>
<tfoot></tfoot>
</table>
my goal:
<table>
<thead></thead>
<div class="scrollbar"><tbody></tbody></div>
<tfoot></tfoot>
</table>
EDIT:
I am using jquery plugin mcustomscrollbar to make sure the tbody part stick at 30% of the screen height when the data rows increase.
Upvotes: 1
Views: 3531
Reputation: 11610
Whell if you really want to do this, then use wrap :
$('table > tbody').wrap('<div class="scrollbar"></div>')
Doc: http://api.jquery.com/wrap/
But as mentioned before, you are creating a not valid HTML. I don't see the purpose for this, unless you are interested in some sort of scrolling table body. But for that I would recommend using some sort of jQuery library or css.
Upvotes: 4
Reputation: 1736
$('.scrollbar').html('<tbody></tbody>')
This will add tbody inside .scrollbar div .
Upvotes: -2
Reputation: 85545
As per your requirement you can do this with css only:
tbody {
display: block;
height: 100px;/*apply your height for the tbody*/
overflow-y: auto;
overflow-x: hidden;
}
Upvotes: 3