Programmer's Guide > Programming and Scripting Techniques > Basic Document Manipulation Using the DOM and AOM > Selecting, Copying, Moving Content > Inserting Text at the Caret
  
Inserting Text at the Caret
This example shows how to insert text in the document where the caret is located using the Range returned by the ADocument.insertionPoint attribute. If the caret is within a text node, the text is inserted into that node. Otherwise, a new text node is inserted before the insertionPoint node.
var doc = Application.activeDocument;
var caret = doc.insertionPoint;
var node = caret.endContainer;
if (node.nodeType == node.TEXT_NODE)
node.insertData(caret.endOffset, " new text ");
else
caret.insertNode(doc.createTextNode(" new text "));