select method (Internet Explorer)

Switch View :
ScriptFree
select method

[This documentation is preliminary and is subject to change.]

Makes the selection equal to the current object.

Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5

Syntax

object.select()

Standards information

Parameters

This method has no parameters.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Remarks

This method causes the current object to be highlighted.

When applied to a TextRange object, the select method causes the current object to be highlighted. The following function uses the findText method to set the current object to the text in the TextRange object. The function assumes an element that contains the text string "text here".


function TextRangeSelect() {
	var r = document.body.createTextRange();
	r.findText("text here");
	r.select();
}


This method produces a shaded rectangle around the elements in the controlRange.

When applied to a controlRange collection, the select method produces a shaded rectangle around the elements in the controlRange. The following function uses the add method to set the current object to an element in the controlRange collection. The function assumes an element with an id of "aaa".



function ControlRangeSelect() {
	var r = document.body.createControlRange();
	r.add(document.all.aaa);
	r.select();
}


This feature might not be available on non-Microsoft Win32 platforms.

 

 

Build date: 3/8/2012

Community Content

Mr. Raymond Kenneth Petry
Remarks, Anomalies
REMARK: This method affects scrollTop, scrollLeft, But does not scroll until focus() ...

ANOMALY #1. For CONTENTEDITABLE, In the single special case where text is selected in or beginning-in the first sub-contained [block-]element, the scrollbar values are set to "0" instead, (Merely positioning the cursor thereto does not evoke this anomaly: text must be selected).

ANOMALY #2. Mousedown on a scrollbar invoking spot.select() causes a scroll-jump to the top, or yanks-back the selection, to view.

REMEDY: grabScroll(); spot.select(); yankScroll() ... stabilizes the scrollbar so that it can advance continually....

COMMENT: This is probably a bug, because, the scrollbar will otherwise jump to the selection while the mouse is held stopped or button released, but jump-return to the 'was'-position if mouse-drag is immediate.

Mr. Raymond Kenneth Petry
select method misbehaves when the selection is at the end of a text node that precedes a block node
If the range is collapsed at the end of a text node that immediately precedes a block node, calling select will cause the selection to move into the following block node, and there is no way to move it back. Creating a range from the new selection will show that the two ranges do not match, having different parentElements.

This seems to be the same as when clicking at the right of the firstChild of a DL DT /DT/DL and the cursor falls to the next line the DT line.... Ray.

REMEDY: SPECIAL CASE #1. A text node is somewhat stabilized by ending it with a </> (whatever; not every text node has a closing tag). Ray.

Imad J
I can confirm the select() bug
I just want to say that I bumped into the same bug that douglasmayle described. Any workarounds?