TextRange object
[This documentation is preliminary and is subject to change.]
Represents text in an HTML element.
Standards information
There are no standards that apply here.
Remarks
Use this object to retrieve and modify text in an element, to locate specific strings in the text, and to carry out commands that affect the appearance of the text.
To retrieve a text range object, apply the createTextRange method to a body, button, or textArea element or an input element that has TYPE text.
Modify the extent of the text range by moving its start and end positions with methods such as move, moveToElementText, and findText. Within the text range, you can retrieve and modify plain text or HTML text. These forms of text are identical except that HTML text includes HTML tags, and plain text does not.
Examples
This example changes the text of a button element to "Clicked" through the TextRange object.
<SCRIPT LANGUAGE="JScript">
var b = document.all.tags("BUTTON");
if (b!=null) {
var r = b[0].createTextRange();
if (r != null) {
r.text = "Clicked";
}
}
</SCRIPT>
See also
Build date: 2/14/2012
It is just the IE8- equivalent of HTML5 W3C startContainer,endContainer,startOffset and endOffset.
- 7/30/2011
- -Munawwar-
1. .text property is unstable (character copy-in/find)
e.g. textrange.text = "·" // ·
Sometimes copies-in as "·" (probably · rendered)
Sometimes copies-in as "•" (probably &boule; rendered)
(This was noticed in copying text from rtf to contenteditable..)
2. object definition is unstable (onclick, on-arrow)
When text-selection is attempted by mouse-click on an object of position:absolute or width:defined, this object is a collection of one html element.
Similarly, When text-selection is attempted by arrow-key, it won't-select: The attempt moves the scrollbar instead.
REMEDY (script):
a. detect .length==1 (otherwise undefined);
b. detect .text==undefined (otherwise defined and maybe blank).
REMEDY (user): doubleclick.
(This was noticed in contenteditable.)
- 2/9/2009
- Mr. Raymond Kenneth Petry
- 2/17/2011
- Mr. Raymond Kenneth Petry