How to Use textRange objects in JavaScript _ javascript skills

Source: Internet
Author: User
This article mainly introduces the usage of textRange objects in JavaScript. For more information, see that TextRange objects are advanced features of Dynamic HTML (DHTML, you can use it to perform many text-related tasks, such as searching and selecting texts. The text range allows you to select characters, words, and sentences from the document. A TextRange object is an abstract object that establishes the start and end positions on the text stream to be displayed in an HTML document.

The following are common attributes and methods of TextRange:

Attribute

BoundingHeight: gets the height of the rectangle bound to the TextRange object.
BoundingLeft gets the distance between the left side of the rectangle bound to the TextRange object and the left side of the rectangle containing the TextRange object.
OffsetLeft: obtains the left position of an object relative to the layout or the parent coordinate specified by the offsetParent attribute.
OffsetTop: obtains the top position of an object relative to the layout or the parent coordinate specified by the offsetParent attribute.
HtmlText gets the width of the rectangle bound to the TextRange object
Set or retrieve text in the range of text
Method

MoveStart: Change the start position of the range
MoveEnd changes the end position of the range
Collapse moves the insert point to the beginning or end of the current range
Move collapse the given text range and move the empty range to the order number.
ExecCommand
Select sets the current selection area to the current object
FindText searches for text in the text and sets the start and end points of the range to enclose the search string.
Using a TextRange Object usually involves three basic steps:

1. Create a text range

2. Set the start point and end point

3. Operate the range

The Code is as follows:


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.