We need to replace portion of the html content with jquery.
original_string = '<option value=\"\"><\/option>\n'
replacing_string = '<option value=""></option> <option value="11">2012/05/09</option> <option value="6">2012/07/03</option> '
$('#id').html().replace(original_string, replacing_string);
The problem is that there are bunch of escape chars in both original and replacing string and the html().replace can not be executed. How to replace a string with escape characters?
Thanks.
Basically we are dynamically adding an empty select option to the page. Based on user input, a select options need to be inserted into the content and be rendered to the screen. The html manipulation happens before rendering.
UPDATE: html content(sorry, it is massy)
<div id="invoice_against_lease" style="display: none;">
<a onclick="add_nest_fields(this, "invoice_items", "<div class=\"fields\">\n<div class=\"input select optional\"><label class=\"select optional\" for=\"invoice_invoice_items_attributes_new_invoice_items_lease_usage_record_id\">Record#:<\/label><select class=\"select optional\" id=\"invoice_invoice_items_attributes_new_invoice_items_lease_usage_record_id\" name=\"invoice[invoice_items_attributes][new_invoice_items][lease_usage_record_id]\"><option value=\"\"><\/option>\n<\/select><\/div>\n<input id=\"invoice_invoice_items_attributes_new_invoice_items__destroy\" name=\"invoice[invoice_items_attributes][new_invoice_items][_destroy]\" type=\"hidden\" value=\"false\" /><a href=\"#\" onclick=\"remove_nest_fields(this); return false;\">Delete<\/a>\n<\/div>\n"); return false;" href="#">Add Record</a>
</div>
var yourOption = $("option");?.replaceWith, makes it much easier than trying to match exact html