Methods


select Method

Makes the selection equal to the current object.

Syntax

object.select()

Return Value

No return value.

Remarks

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();
}

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.

Standards Information

This method is defined in World Wide Web Consortium (W3C) Document Object Model (DOM) Level 1 World Wide Web link.

Applies To

TextRange, controlRange, ControlRangeCollection Constructor, TextRange Constructor
Tags :


Community Content

douglasmayle
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.
Tags : bug

Page view tracker