Export (0) Print
Expand All
14 out of 32 rated this helpful - Rate this topic

createTextRange method

Creates a TextRange object for the element.

Syntax

object.createTextRange()

Parameters

This method has no parameters.

Return value

Type: TextRange

Returns  a TextRange object if successful, or null otherwise.

Standards information

There are no standards that apply here.

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>
  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>
  var coll = document.all.tags("button");
  if (coll != null && coll.length > 0) {
    var rng = coll[0].createTextRange();
    rng.text = "Clicked";
  }
</script>

See also

body
button
input type=button
input type=email
input type=hidden
input type=number
input type=password
input type=range
input type=reset
input type=search
input type=submit
input type=tel
input type=text
input type=url
textArea

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.