Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
collapseToStart

collapseToStart method

Collapses, or sets the insertion point or caret at the beginning of a selection object.

HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.1Internet Explorer 9

 

Syntax


HRESULT retVal = object.collapseToStart();

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.

Standards information

Remarks

Raises an INVALID_STATE DOMException if there are no Ranges in the selection.

Examples

The following code example puts the caret or insertion point at the beginning of the selected text.


<!DOCTYPE html>
<html>
<head>
   <title>Collapse to Start Example</title>
    <script type="text/javascript">
        function SelectAtStart () {
            if (window.getSelection) {       
                var selection = window.getSelection ();
                selection.collapseToStart ();
            }
        }
    </script>
</head>
<body>
<p>
    <div contenteditable="true" style="width:300px;">
        Select some text from this paragraph, and then click the following button.
        When you click the button, the caret, or insertion point, is set to the beginning of your selection.
    </div>
 </p>  
 <p><input type="button" name="test" value="Set caret" onclick="SelectAtStart ()" /> </p>
</body>
</html> 

See also

IHTMLSelection::collapseToEnd

 

 

Community Additions

ADD
Show:
© 2015 Microsoft