isCollapsed property (selectionRange)
Returns a Boolean value that indicates whether the anchor and focus points of the current selectionRange object are in the same position.
Note: The selectionRange object and its isCollapsed property are supported in Internet Explorer from version 9.The selectionRange object represents the current selection and every Range object that belongs to the selectionRange object represents a contiguous part of the selection. If there is no selection in the document, then no Range object belongs to the selectionRange object.
In that case, the isCollapsed property returns true.
You can get the count of the Range objects that belong to the current selection with the rangeCount property.
- In Internet Explorer, Opera, Google Chrome, Safari and Firefox before version 3, at most one Range can belong to the selectionRange object, because text selection is always a contiguous part of the DOM hierarchy. If one Range object belongs to the current selection, then the isCollapsed property indicates whether it is empty or not.
- In Firefox from version 3, multiple areas of text can be selected by holding down the CTRL key while selecting. If multiple ranges are added to the selection (by the user or by script, see the addRange method), then use the collapsed property of the Range objects for similar functionality.
You can find the related objects in the Supported by objects section below.
This property is read-only.
Boolean that indicates the relation between the anchor and focus points.
One of the following values:
|The anchor and focus points are in different positions.|
|The anchor and focus points are at the same position.|
Default: this property has no default value.
Example HTML code 1:
This example illustrates the use of the isCollapsed property:
Did you find this example helpful?
User Contributed Comments