I have a string of text that has the value of the selected text. Id like to do a replace() of this text in a given div of text.
so I know I can do that with the following:
myelement.replace(/foo/g, 'bar');
However I need to do it with my string ie:
myelement.replace(/*mystring*/g, 'bar');
So I tried:
mystring = '/'+mystring+'/g';
myelement.replace(mystring, 'bar');
Which didnt work, so i tried (which i knew wouldn't work):
myelement.replace(/+mystring+/g, 'bar');
So how can i do this?
I've coded something up for you guys in jsfiddle --> HELP ME PLEASE!