I have trouble with replacing certain values in a variable that contains captured html.
I’ll let the code explain what I want to accomplish.
lest say:
last_id = 1;
data.id = 2;
the code:
/*prepare new edit,delete button*/
var controls = $('table#option_groups tr:last td:last').html();
outputting var controls will return:
<a href="stuff/edit/1">Edit</a>
<a href="stuff/delete/1">Delete</a>
trying to replace\update edit button:
//replacing edit button
controls.replace('/edit/'+last_id, '/edit/'+data.id);
outputting controls after replace:
<a href="stuff/edit/1">Edit</a>
<a href="stuff/delete/1">Delete</a>
desired output:
<a href="stuff/edit/2">Edit</a>
<a href="stuff/delete/1">Delete</a>
So the question is: How do you replace occurance of string in a varible that contains captured html.
Thank you!
You can do this in one line of code:
Output: