You are here: Reference > JavaScript > client-side > HTML DOM > methods > insertData (comment, CommentNode, TextNode)
insertData method (comment, CommentNode, TextNode)
Inserts text content into the current TextNode, CommentNode or comment element at the specified position.
The appendData, deleteData and replaceData 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 the start position of the insertion. Negative values and values greater than the length of the current object raise an exception. | |||||||
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 insertData method:
|
||||
<head> <script type="text/javascript"> function InsertText () { var textContainer = document.getElementById ("textContainer"); var firstTextNode = textContainer.firstChild; firstTextNode.insertData (18, "inserted text "); } </script> </head> <body> <div id="textContainer">Insert text here: before this</div> <br /><br /> <button onclick="InsertText ()">Insert some text into the text above!</button> </body> |
||||
|
||||
Did you find this example helpful?
|
Supported by objects:
Related pages:
External links:
User Contributed Comments