Note that there are some explanatory texts on larger screens.

plurals
  1. POproblem with jquery : minipulating val() property of element
    primarykey
    data
    text
    <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>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload