createTextRange method (body, input, textarea, ...)
Creates a new TextRange object and aligns its start and end points to the text content of the current element.
body and some other HTML elements support the createTextRange method. If you need to create a TextRange object that is adjusted to the contents of an element that does not support the createTextRange method, then use the createTextRange method on the body and invoke the moveToElementText method with the required element.Only the
The TextRange object represents a contiguous part of the document. For further details, see the page for the TextRange object.In Firefox, Opera, Google Chrome, Safari and Internet Explorer from version 9, the Range object provides functionality similar to the TextRange object. To create a new Range object, use the createRange method.
You can find the related objects in the Supported by objects section below.
Returns the newly created TextRange object.
Example HTML code 1:
This cross-browser example shows how the contents of an element can be deleted with range objects:
Did you find this example helpful?
User Contributed Comments