Javascript Code to Replace a Word in a String
This code will Replace a Word in a String using Javascript Javascript <!DOCTYPE html> <html> <head> <title>JavaScript Replace a Word in a String</title> </head> <body> <p id="myText">My favorite color is red</p> <button type="button" onclick="strReplace();">Replace</button> </body> <script> function strReplace(){ var myStr = 'My favorite color is red'; var newStr = myStr.replace(/red/g, "purple"); document.getElementById("myText").innerHTML = newStr;} </script> </html> Click here to run this code Share with Friends More Free Code Examples: Javascript Substitution Cipher Javascript Easy Battleship Game Hello World in 10 Programming Languages Try these Fun Games by Bobbie: Travel Blast Game New York Play ...