Replace characters in a string - replace()
How to replace a specified value with another value in a string.
<html>
<body>
<p id="demo">Click the button to replace "Microsoft" with "W3Schools".</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
var str="Visit Microsoft!";
var n=str.replace("Microsoft","W3Schools");
document.getElementById("demo").innerHTML=n;
}
</script>
</body>
</html>
How to replace a specified value with another value in a string.
<html>
<body>
<p id="demo">Click the button to replace "Microsoft" with "W3Schools".</p>
<button onclick="myFunction()">Try it</button>
<script type="text/javascript">
function myFunction()
{
var str="Visit Microsoft!";
var n=str.replace("Microsoft","W3Schools");
document.getElementById("demo").innerHTML=n;
}
</script>
</body>
</html>
No comments:
Post a Comment