Click to Rate and Give Feedback
MSDN
MSDN Library
Web Development
HTML and CSS
Methods
 createTextRange Method

  Switch on low bandwidth view
createTextRange Method

Creates a TextRange object for the element.

Syntax

oTextRange = object.createTextRange()

Return Value

Returns a TextRange object if successful, or null otherwise.

Remarks

Use a text range to examine and modify the text within an object.

Examples

This example uses the createTextRange method to create a text range for the document, and then uses the text range to display all the text and HTML tags in the document.

<SCRIPT LANGUAGE="JScript">
var rng = document.body.createTextRange( );
if (rng!=null) {
    alert(rng.htmlText);
}
</SCRIPT>

This example uses the createTextRange method to create a text range for the first button element in the document, and then uses the text range to change the text in the button.

<SCRIPT LANGUAGE="JScript">
var coll = document.all.tags("BUTTON");
if (coll!=null && coll.length>0) {
    var rng = coll[0].createTextRange();
    rng.text = "Clicked";
}
</SCRIPT>

Standards Information

There is no public standard that applies to this method.

Applies To

BODY, BUTTON, INPUT type=button, INPUT type=hidden, INPUT type=password, INPUT type=reset, INPUT type=submit, INPUT type=text, TEXTAREA, HTMLBodyElement Constructor, HTMLButtonElement Constructor, HTMLInputElement Constructor, HTMLTextAreaElement Constructor
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker