How to use jQuery to add only two tds' to one tr ...
I have a table. I want the maximum number of tds per line .. something like this
if($("td").length) == 0){ // get the count of existing tds $("table").append("<tr>"); } $("table").append("<td>Something</td>"); if($("td").length) == 2){ // if it hit two tds' in this tr then close the tag $("table").append("</tr>"); } // this is not a valid example, just trying to deliver my point
this is not a loop, it is added on click, so let's say I pressed 5 times, I have to get this
<tr> <td>Someting</td> <td>Someting</td> </tr> <tr> <td>Someting</td> <td>Someting</td> </tr> <tr> <td>Someting</td> </tr>
source share