You are here: Reference > JavaScript > client-side > HTML DOM > methods > replaceData (comment, CommentNode, TextNode)
replaceData method (comment, CommentNode, TextNode)
Replaces the specified part of the text content of the current TextNode, CommentNode or comment element with a new text.
The appendData, deleteData and insertData methods and the data property can also be used to manipulate the text content of the current element.
Syntax:
You can find the related objects in the Supported by objects section below.
Parameters:
Required. Integer that specifies start position of the contents to remove. | |||||||
Required. Integer that specifies the number of characters to remove. | |||||||
Required. String that specifies the text to insert. |
Return value:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the replaceData method:
|
||||
<head> <script type="text/javascript"> function ReplaceText () { var textContainer = document.getElementById ("textContainer"); var firstTextNode = textContainer.firstChild; firstTextNode.replaceData (0, 5, "Hi"); } </script> </head> <body> <div id="textContainer">The first five characters of this text will be replaced.</div> <br /><br /> <button onclick="ReplaceText ()">Replace the first five characters of the text above!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments