JQuery add form elements iterate ids
<p>I don't care about the content in the form, just want to add a new set of them every time I click add. I will however be adding some conditional fields. But with that in mind, do I actually need to iterate ids? And is the clone event the best way to handle this?</p>

<pre><code>&lt;div id="wrapper"&gt;
&lt;div id="condition-1"&gt;
  &lt;select id="trigger-1" class="trigger"&gt;
      &lt;option value="0"&gt;Select...&lt;/option&gt;
      &lt;option value="1"&gt;View Count&lt;/option&gt;
      &lt;option value="2"&gt;Comment Count&lt;/option&gt;
  &lt;/select&gt;
  &lt;select id="operator-1" class="operator"&gt;
      &lt;option value="0"&gt;Select...&lt;/option&gt;
      &lt;option value="1"&gt;Is Greater Then&lt;/option&gt;
      &lt;option value="2"&gt;Less Than&lt;/option&gt;
  &lt;/select&gt;
  &lt;div id="input-1" class="input"&gt;
      &lt;input id="number-1"&gt;&lt;/input&gt;
  &lt;/div&gt;
&lt;/div&gt;
</code></pre>

<p></p>

<pre><code>&lt;div id="add-1" class="add"&gt;Add more&lt;/div&gt;
</code></pre>

<p>I've been digging through a lot of examples of jQuery .clone() ,have not been able to apply any examples to a structure like this. My goal is to add a new set of form elements every time I click "Add more". I don't care if it clones the actual content, just want to clone and then iterate the id's appropriately.</p>

<p>I tried using something similar to:</p>

<pre><code>var cur_num = 1;

var cloned = $("#condition-" + cur_num).clone(true, true).get(0);

++cur_num;

cloned.id = "condition-" + cur_num;                  // Change the div itself.
$(cloned).find("*").each(function(index, element) {   // And all inner elements.
    if(element.id)
    {
        var matches = element.id.match(/(.+)_\d+/);
        if(matches &amp;&amp; matches.length &gt;= 2)            // Captures start at [1].
            element.id = matches[1] + "-" + cur_num;
    }
});

$(cloned).appendTo($("#condition-wrapper"));*/
</code></pre>

<p>The above block of code will clone and append the block I want. But as it iterates the first condition id to #condition-2, every block after is coming up #condition-2 and I have no idea how to change the children of condition-1 to trigger-2 operator-2. Any help is appreciated, thank you!</p>
