I have a database that outputs a table in a single row, I need to use jQuery to split the single row into multiple rows of three columns, it would also be good if I could change a value to make it multiple rows of 4 or 5 in the future.
HTML Output example
<table class="staff">
<tbody>
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
<td>10</td>
<td>11</td>
<td>12</td>
<td>13</td>
</tr>
</tbody>
</table>
Result required
Note, I can not write jQuery, so I manipulate exisiting scripts, I have found the script below, it creates multiples of 2 columns per row however when I try and mess with the values I can't get it to display 3 columns per row.
jQuery
$("table.staff td").each(function(index) {
var odd = isOdd((index + 1));
if (odd) {
$("table.staff tbody").append($("<tr>"));
}
$("table.staff tr").last().append($(this));
});
$("table.staff tr").first().remove();
function isOdd(num) {
return num % 2;
}
Any help would be appreciated
Thanks
