I want to replace multiple occurrences of 'text1' with 'text2', in '#area', here is my code that works just fine:
var replaced = $('#area').html().replace(/text1/g, 'text2');
$('#area').html(replaced);
But imagine the 'text1' is a value of an input box, so:
var search = $('#blah').val();
var replaced = $('#area').html().replace(/search/g, 'text2'); <--- HERE IS THE PROBLEM
$('#area').html(replaced);
As you can see in the second line, I did /search/g
but it's not working, how should I put the search
value there?