Page 227 - Web_Application_v2.0_C12_Fb
P. 227
document.getElementById("demo1").innerHTML = text.substring(7, 17);
</SCRIPT>
</BODY>
</HTML>
Output:
3. The replace() Method: The replace() method searches a string for a specified value and replaces it with
another value.
Example 33: To demonstrate the use of replace method
<!DOCTYPE HTML>
<HTML>
<HEAD>
<TITLE>replace() Method</TITLE>
</HEAD>
<BODY>
<H2>The replace() Method</H2>
<P>The replace() method replaces a specified value in a string.</P>
<P id="demo1"></P>
<SCRIPT>
var text = "I love Python!";
document.getElementById("demo1").innerHTML = text.replace("Python ",
"JavaScript");
</SCRIPT>
</BODY>
</HTML>
Output:
JavaScript Part 2 225

