Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>you need to use delegated on event for dynamically added elements</p> <p>try this</p> <pre><code> $('#container').on('click','#newField_' + divid, function () { ..... </code></pre> <p>it would be real easy if you use class instead of <code>id</code>...</p> <pre><code>&lt;div class="addNew" class="new"&gt; .. &lt;input type="text" class="input" value="Here goes your stuff"&gt; &lt;input type="button" class="newField" value="New Field For Stuff"&gt; </code></pre> <p>and use class selector..</p> <pre><code>$('#container').on('click','.newField', function () { ..... </code></pre> <p>no need to take care of <code>divid</code> and <code>select</code> and its counter</p> <p><strong>note: you missed name attribute of your input element</strong></p> <p><strong>updated</strong></p> <p>using <code>clone()</code> since i think you are creating the same element and appending it... and you can post you name as array to PHP so that you can use loop to get all the inputs value</p> <pre><code>$('#container').on('click','.newField', function () { var newthing=$('div.addNew:first').clone() .find('.newField') .removeClass('newField') .addClass('remove') .val('Remove Field!') .end(); $('#container').append(newthing); }); $('#container').on('click','.remove', function () { $(this).parent().remove(); }); $('#add').on('click', function () { var thing=$('div.addNew:first').clone(); $('#container').append(thing); }); </code></pre> <p>fiddle <a href="http://jsfiddle.net/bipen/ADgAE/3/" rel="nofollow">here</a></p>
    singulars
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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