jquery wrap (dynamic elements)
<p>so I have been researching this all morning- and I'm pretty sure the code is correct but to explain I am trying to include a table in the dynamically generated input, so need the tr/td in there. I have reviewed the html/wrap/append etc. functions to no avail... :-(</p>

<p>See the comment there for the full script but really this is the meat of it. Any help would be greatly appreciated. </p>

<p>I tried the wrap and document writes but it doesn't like it. what am I missing???</p>

<pre><code>$(document).ready(function() {
    $('#btnAdd').click(function() {
        var num     = $('.clonedInput').length; // how many "duplicatable" input     fields we currently have
        var newNum  = new Number(num + 1);      // the numeric ID of the new input     field being added
        //http://charlie.griefer.com/blog/2009/09/17/jquery-dynamically-adding-    form-elements/
        // create the new element via clone(), and manipulate it's ID using newNum     value
        var newElem = $('#input' + num).clone().attr('id', 'input' +     newNum).wrap('&lt;td /&gt;');
        // manipulate the name/id values of the input inside the new element
        newElem.children(':first').attr('id', 'name' + newNum).attr('name', 'name'     + newNum).val('');
        newElem.children(':second').attr('id', 'amt' + newNum).attr('name', 'amt'     + newNum).val('');
        newElem.children(':third').attr('id', 'value' + newNum).attr('name',     'value' + newNum).val('');
        newElem.children(':fourth').attr('id', 'test' + newNum).attr('name',     'test' + newNum).val('');
        // insert the new element after the last "duplicatable" input field
        document.write("&lt;tr&gt;");
        $('#input' + num).after(newElem);
        document.write("&lt;/tr&gt;");
</code></pre>
