collapse method (Range, TextRange)
Moves the start point of a range to its end point or vice versa.
Note: The Range object and its collapse method are supported in Internet Explorer from version 9.When the start and end points of a range are at the same position, then the range is empty.
- For Range objects, use the startContainer, startOffset, endContainer and endOffset properties to retrieve the boundary points and the collapsed property to check whether a range is collapsed.
- For TextRange objects, use the getClientRects method to retrieve the exact shape and check the length of the text retrieved with the text property to detect whether a range is collapsed.
You can find the related objects in the Supported by objects section below.
Optional. Boolean that indicates the direction of the collapsing.
One of the following values:
This method has no return value.
Example HTML code 1:
This example illustrates the use of the collapse method:
Did you find this example helpful?
User Contributed Comments