I wrote a quick function to create a set of radio buttons, three per table row. I would like some feedback about how I can shorten this bit of code using algebraic functions, or different jQuery functionality.var arr = [ earth, mars, jupiter, saturn, venus, argus, pluto, janus, canary, orange, butter pineapple, eventual bliss];var obj = { one:earth, two:mars, three:jupiter, four:saturn, five:venus };var start = ; end = ;var count = 0;$(#radio_container).append(<table>);     $.each(arr, function(i, val) {        if(count == 3)        {            start = <tr>;            end = </tr>            count= 0;        }        $(#radio_container).append(start);            $(#radio_container).append(<td><input name='finalcategory' type='radio' value='+val+'></input></td><td class='style3'>+val+</td>);        $(#radio_container).append(end);          count++;        start = ;        end = ;    });$(#radio_container).append(</table>);
Set of radio buttons
javascript;jquery
Here's how I would probably tackle this:var arr = [ earth, mars, jupiter, saturn, venus, argus, pluto, janus, canary, orange, butter pineapple, eventual bliss];var obj = { one:earth, two:mars, three:jupiter, four:saturn, five:venus };// Create the table here and attach it to your document.var $table = $('<table>').appendTo('#radio_container'),    // also, create the scope of $tr so we can keep using it.    $tr;$.each(arr, function(k,v){  // if it's a multiple of 3, create a new row and attach  // it to the table  if ((k % 3) == 0){    $tr = $('<tr>').appendTo($table);  }  // create the data cell  $('<td>',{    // add a radio input element within    'html':$('<input>',{      'name':'finalcategory',      'type':'radio',      'value':v    })  }).appendTo($tr); // attach it to the row  // create the second cell, style and populate it,  // and also attach it to the row.  $('<td>',{    'class':'style3'  }).text(v).appendTo($tr);});Working example, and the notes:Use jQuery to build the objects, don't use <html> strings.With a little refactoring, you can use the pre-created objects to your advantage and rid yourself of a counter variable.You can also use modulo (%) to figure out which row you're on.Some other things:jQuery allows you to specify an object ({}) as a second parameter which will set the attributes of the object it's creating (see how I've done it to mimic your code).Use .text() whenever possible to avoid injecting foul information in to the markup. .text() will sanitize the data for you--let it.EDIT Feel free to also heed the advice of a comment about not showing the table until it has completed rendering. This can be done very simply using .hide() and .show() as shown in this example