problem with jquery : minipulating val() property of element
<p>Please help! </p>

<p>I have some form elements in a div on a page:</p>

<pre><code>&lt;div id="box"&gt;
   &lt;div id="template"&gt;
       &lt;div&gt;
       &lt;label for="username"&gt;Username&lt;/label&gt;
       &lt;input type="text" class="username" name="username[]" value="" / &gt;
       &lt;label for="hostname"&gt;hostname&lt;/label&gt;
       &lt;input type="text" name="hostname[]" value=""&gt;
       &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p>using jquery I would like to take a copy of #template, manipulate the values of the inputs and insert it after #template so the result would look something like:</p>

<pre><code>&lt;div id="box"&gt;
   &lt;div id="template"&gt;
       &lt;div&gt;
       &lt;label for="username"&gt;Username&lt;/label&gt;
       &lt;input type="text" class="username" name="username[]" value="" / &gt;
       &lt;label for="hostname"&gt;hostname&lt;/label&gt;
       &lt;input type="text" name="hostname[]" value=""&gt;
       &lt;/div&gt;
    &lt;/div&gt;
       &lt;div&gt;
       &lt;label for="username"&gt;Username&lt;/label&gt;
       &lt;input type="text" class="username" name="username[]" value="paul" / &gt;
       &lt;label for="hostname"&gt;hostname&lt;/label&gt;
       &lt;input type="text" name="hostname[]" value="paul"&gt;
       &lt;/div&gt;
&lt;/div&gt; 
</code></pre>

<p>I am probably going about this the wrong way but the following test bit of javascript code run in firebug on the page does not seem to change the values of the inputs.</p>

<pre><code>var cp = $('#template').clone();

cp.children().children().each( function(i,d){
    if( d.localName == 'INPUT' ){
        $(d).val('paul'); //.css('background-color', 'red');
     }
    });
$("#box").append(cp.html());
</code></pre>

<p>although if I uncomment "//.css('background-color', 'red');" the inputs will turn red.</p>
