I have the following
// 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
<ul class="sortable_fields">
</ul>
<p id="add_field"><%= link_to_add_fields "Add Trip Day", f, :trip_days %></p>
I am using Rails, you can gracefully ignore it. When I add a field, the new HTML code as depicted in content.replace(regexp, new_id) will show after <p>. For example:
If content.replace(regexp, new_id) is <li>Test</li>, it will result:
<ul class="sortable_fields">
</ul>
<p id="add_field"><%= link_to_add_fields "Add Trip Day", f, :trip_days %></p>
<li>Test</li>
instead of:
<ul class="sortable_fields">
<li>Test</li>
</ul>
<p id="add_field"><%= link_to_add_fields "Add Trip Day", f, :trip_days %></p>
I know I could change the .before(), but since there are HTML contents which will be generated by the system, I rather not touch it. How should I change the jQuery?
Many thanks.
To get from ‘a’ to ‘ul’