/ Published in: JavaScript
Normal replace() function only replaces first instance.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<script type="text/javascript"> var visitorName = "Chuck"; var myOldString = "Hello username! I hope you enjoy your stay username."; var myNewString = myOldString.replace(/username/g, visitorName); document.write("Old string = " + myOldString); document.write("<br />New string = " + myNewString); </script>
URL: http://www.tizag.com/javascriptT/javascript-string-replace.php