Add HTML elements before a specific tag for jQuery
<p>I have the following</p>

<pre><code>// jQuery
function add_fields(link, association, content) {
  var new_id = new Date().getTime();
  var regexp = new RegExp("new_" + association, "g");
  $(link).parent().before(content.replace(regexp, new_id));//.prev().hide().show("slow");
}

// HTML
&lt;ul class="sortable_fields"&gt;
&lt;/ul&gt;
&lt;p id="add_field"&gt;&lt;%= link_to_add_fields "Add Trip Day", f, :trip_days %&gt;&lt;/p&gt;
</code></pre>

<p>I am using Rails, you can gracefully ignore it. When I add a field, the new HTML code as depicted in <code>content.replace(regexp, new_id)</code> will show after <code>&lt;p&gt;</code>. For example:</p>

<p>If <code>content.replace(regexp, new_id)</code> is <code>&lt;li&gt;Test&lt;/li&gt;</code>, it will result:</p>

<pre><code>&lt;ul class="sortable_fields"&gt;
&lt;/ul&gt;
&lt;p id="add_field"&gt;&lt;%= link_to_add_fields "Add Trip Day", f, :trip_days %&gt;&lt;/p&gt;
&lt;li&gt;Test&lt;/li&gt;
</code></pre>

<p>instead of:</p>

<pre><code>&lt;ul class="sortable_fields"&gt;
  &lt;li&gt;Test&lt;/li&gt;
&lt;/ul&gt;
&lt;p id="add_field"&gt;&lt;%= link_to_add_fields "Add Trip Day", f, :trip_days %&gt;&lt;/p&gt;
</code></pre>

<p>I know I could change the <code>.before()</code>, but since there are HTML contents which will be generated by the system, I rather not touch it. How should I change the jQuery?</p>

<p>Many thanks.</p>
