replacing multiple instances in javascript string

label Computer Science
account_circle Unassigned
schedule 1 Day
account_balance_wallet $5

what is the best way to replace multiple instances of the same string in javascript?

Mar 20th, 2015

<!DOCTYPE html>

<html>

<body>

<button onclick="replaceText()">Replace</button>

<p id="textbox"> The best way to replace multiple instances of the same string in javascript.<br>

The best way to replace multiple instances of the same string in javascript.<br>

The best way to replace multiple instances of the same string in javascript.

</p>

<script>

function replaceText(){            

    var s1 = document.getElementById("textbox").innerHTML;

    var s2 = s1.replace(/way/gi,"method");

     document.getElementById("textbox").innerHTML = s2;

}

</script>

</body>

</html>

Hi...try this code.... this javascript + html code replacing the multiple instances of same string. In this example,  " way"  string is replaced by "method". In this "gi"  regexp is used for global case-insensitive search.

Mar 21st, 2015

Did you know? You can earn $20 for every friend you invite to Studypool!
Click here to
Refer a Friend
...
Mar 20th, 2015
...
Mar 20th, 2015
Jun 23rd, 2017
check_circle
Mark as Final Answer
check_circle
Unmark as Final Answer
check_circle
Final Answer

Secure Information

Content will be erased after question is completed.

check_circle
Final Answer