Creating chunks of HTML with jQuery I am working on an online ordering form and am looking for some advice about my jQuery.  I am re-developing the code base for this ordering form and improving what was created by a web design group years ago.  The existing form uses Javascript to dynamically generate a new line of item information when the starts typing in the form.  Reviewing the existing code there is close to 100 lines of JS (many being DOM manipulations) to add the HTML elements and so forth.  I could redo it in JS no problem, but I would like to reduce this amount of code and convert the solution to jQuery. It is already in use for other parts of the site so I may as well utilize it.  

I've written a function to facilitate this that I am toying around with to get the functionality down.

function createNewRow() {
    //createNewRow.rc = 1;  
    if(typeof createNewRow.rc == 'undefined') {
        createNewRow.rc = 1;
    }
    //Select the existing parent div
    var div = $('div#div');
    //Create a child div (container to the form elements)
    var cell = $('&lt;div class="block itemRow"&gt;&lt;/div&gt;');
    //Create "cells" (really divs) and form elements

    itemQty = $('&lt;div class="itemQty"&gt;&lt;/div&gt;');
    itemQty.append('&lt;p&gt;Quantity&lt;p&gt;')
           .append('&lt;input type="text" size="5" class="inputbox" name="ooItem[' + createNewRow.rc + '][qty]" id="' + createNewRow.rc + '" /&gt;');

    itemUnit = $('&lt;div class="itemUnit"&gt;&lt;/div&gt;');
    itemUnit.append('&lt;p&gt;UOM&lt;/p&gt;');
    unitSlct = $('&lt;select name="ooItem[' + createNewRow.rc + '][unit]"&gt;&lt;/select&gt;');
    unitSlct.append('&lt;option value="pc"&gt;PCS&lt;/option&gt;')
            .append('&lt;option value="sq"&gt;SQ&lt;/option&gt;')
            .append('&lt;option value="lf"&gt;LF&lt;/option&gt;')
            .append('&lt;option value="ea"&gt;EA&lt;/option&gt;');
    itemUnit.append(unitSlct);


    itemDesc = $('&lt;div class="itemDescription"&gt;&lt;/div&gt;');
    itemDesc.append('&lt;p&gt;Description&lt;/p&gt;')
            .append('&lt;input type="text" class="inputbox" name="ooItem[' + createNewRow.rc +'][description]" /&gt;');

    itemColor = $('&lt;div class="itemColor"&gt;&lt;/div&gt;');
    itemColor.append('&lt;p&gt;Color&lt;/p&gt;')
             .append('&lt;input type="text" class="inputbox" name="ooItem[' + createNewRow.rc +'][color]" /&gt;');

    itemText = $('&lt;div class="itemTexture"&gt;');
    itemText.append('&lt;p&gt;Texture&lt;/p&gt;');
    textSlct = $('&lt;select class="inputbox" name="ooItem[' + createNewRow.rc +'][texture]"&gt;&lt;/select&gt;');
    textSlct.append('&lt;option value="rough"&gt;Rough&lt;/option&gt;')
            .append('&lt;option value="smooth"&gt;Smooth&lt;/option&gt;');
    itemText.append(textSlct);

    cell.append(itemQty)
        .append(itemUnit)
        .append(itemDesc)
        .append(itemColor)
        .append(itemText);


    //Append child div to the parent div
    div.append(cell);
    //Increase the row count
    createNewRow.rc++;
}


JSFiddle is here: http://jsfiddle.net/McFRV/3/

From a functionality standoint this works fine.  HTML rows are created as I like (minus the presentation layer of course) and the form information passes to the webserver correctly with all the information in the right places.  What is bugging me a bit is how "dirty" this code appears to me.  It seems as if using jQuery to make all that HTML in a bunch of strings is uncanny. Is there a better way to create chunks of HTML other than how I am going about it, or am I simply stressing about nothing?
You could always clean it up using jQuery tmpl

https://github.com/BorisMoore/jquery-tmpl

You would just define the HTML of the templates, and then you could add them to the rows.