Tuesday, 2 April 2013

JavaScript replace() Method


 JavaScript replace() Method :


<!DOCTYPE html>
<html>


<body>
<p id="demo">Hello Steve</p>

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

<script>
function myFunction()
{
var str=document.getElementById("demo").innerHTML;
var n=str.replace("Steve","jhon");
document.getElementById("demo").innerHTML=n;
}
</script>

</body>
</html>


Output :
Click the Replace button to replace "steve" with "jhon" in the paragraph below

No comments:

Post a Comment