Skip to main content
selection object

[selection is no longer supported. Starting with Internet Explorer 11, use getSelection. For info, see Compatibility changes.]

Represents the active selection, which is a highlighted block of text or other elements in the document that a user or a script can carry out some action on.


The selection object has these types of members:


The selection object has these methods.


Clears the contents of the selection.


Creates a TextRange object from the current text selection, or a controlRange collection from a control selection.


Creates a TextRange object collection from the current selection.


Cancels the current selection, sets the selection type to none, and sets the item property to null.



The selection object has these properties.



Retrieves the type of selection.


Retrieves the name of the selection type.


Standards information

There are no standards that apply here.


You can use the selection object as input from the user to identify which portion of the document to act on, or as output to the user to show the results of an action.

Users and scripts can create selections. Users create selections by dragging the mouse over a portion of the document. Scripts create selections by calling the select method on a text range or similar object. To get the active selection, apply the selection keyword to the document object. To carry out work on a selection, create a text range object from the selection using the createRange method.

A document can have only one selection at a time. The selection has a type that determines whether it is empty or contains a block of text or elements. Although an empty selection contains nothing, you can use it to mark a position in the document.