Note that there are some explanatory texts on larger screens.

plurals
  1. POjQuery - Add new div on click after last matching div
    primarykey
    data
    text
    <p>I want to add new div on click @ the end of last match.</p> <pre><code> &lt;form id="form"&gt; &lt;div class="border item-block"&gt; &lt;p&gt;&lt;b&gt;Color :&lt;/b&gt; silver &lt;/p&gt; &lt;input type="hidden" name="available_colors[silver][color_name]" value="silver"&gt; &lt;input type="text" name="available_colors[silver][color_image]" value="SM-9436RE_B_BEAUTY.JPG"&gt; &lt;/div&gt; &lt;a style = "float : left; margin-top: 50px" class="button add"&gt;Add&lt;/a&gt; &lt;/form&gt; </code></pre> <p>On click I want to create div with input as this attr available_colors[NEW][0][color_name] and so on.</p> <p>Like this</p> <pre><code> &lt;form id="form"&gt; &lt;div class="border item-block"&gt; &lt;p&gt;&lt;b&gt;Color :&lt;/b&gt; silver &lt;/p&gt; &lt;input type="hidden" name="available_colors[silver][color_name]" value="silver"&gt; &lt;input type="text" name="available_colors[silver][color_image]" value="SM-9436RE_B_BEAUTY.JPG"&gt; &lt;/div&gt; &lt;div class="border item-block"&gt; &lt;p&gt;&lt;b&gt;Color :&lt;/b&gt; &lt;input type="text" name="available_colors[NEW][0][color_name]" value=""&gt;&lt;/p&gt; &lt;input type="text" name="available_colors[NEW][0][color_image]" value=""&gt; &lt;/div&gt; &lt;a style = "float : left; margin-top: 50px" class="button add"&gt;Add&lt;/a &lt;/form&gt; </code></pre> <p>On second click want to add this div</p> <pre><code>&lt;div class="border item-block"&gt; &lt;p&gt;&lt;b&gt;Color :&lt;/b&gt; &lt;input type="text" name="available_colors[NEW][1][color_name]" value=""&gt;&lt;/p&gt; &lt;input type="text" name="available_colors[NEW][1][color_image]" value=""&gt; &lt;/div&gt; </code></pre> <p>I try this approach but i am not getting filed. I tried to clone the last div but i dont know how I can switch all input name attributes. </p> <pre><code>$('a.add').click(function(){ var form, fields; //$('.item-block').last().clone().insertAfter($('.item-block').last()); form = $("#form"); fields = form.find("input[name^='available_colors[NEW]']"); alert(fields[0]); }); </code></pre> <p>Can some one advice me know this?</p> <p>Thank You in advance. </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.
 

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