Javascript replace function example <!DOCTYPE html> <html> <body> <p>Javascript rep

Javascript replace function example <!DOCTYPE html> <html> <body> <p>Javascript replace function example</p> <p>
Generic placeholder image

Mukesh R

Javascript replace function example

<!DOCTYPE html>
<html>
<body>

<p>Javascript replace function example</p>
<p>Click here the link below to change Mukesh to Ratheesh</p>

<div id="divElement">Hello Mukesh</div>

<button onclick="myJavascriptFunction()">Try it</button>

<script>
function myJavascriptFunction() {
    var str = document.getElementById("divElement").innerHTML; 
    var res = str.replace("Mukesh", "Ratheesh");
    document.getElementById("divElement").innerHTML = res;
}
</script>

</body>
</html>