[This documentation is preliminary and is subject to change.]
Makes the selection equal to the current object.
![]() |
Syntax
object.select()Standards information
- Document Object Model (DOM) Level 2 HTML Specification, Section 1.6.5
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
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.
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.
