I have a string and some text (name attr) should be replaced with dynamic text. For example
options[team_member][0][name] will be replaced with options[team_member][1][name].
What far i did:
var current = 1;
var block = jQuery('#contents').html();
var replace_str = 'options[team_member]['+(current-1)+']';
var replace_with = 'options[team_member]['+(current)+']';
/* replace only first match */
var rep_block = block.replace(replace_str,replace_with);
/* replace nothing */
// var rep_block = block.replace(/replace_str/g,replace_with);
/* replace nothing */
// var rep_block = block.replace(/(replace_str)/g,replace_with);
alert(rep_block);
Please check full code in jsFiddle
I cannot find the way how can i solve this. Please help me. Thanks in advance.