Partilhar via


removeAllRanges method

Removes all ranges from a selection.

 

Syntax

HRESULT retVal = object.removeAllRanges();

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

IHTMLSelection::removeAllRanges can remove invisible carets or insertion points that result when the Collapse method is applied to a selection.

Examples

This example uses IHTMLSelection::removeAllRanges to clear a selection from text or elements.

<!DOCTYPE html>
<html>
    <head>
    <title>Remove All Ranges Example</title>        
        <script type="text/javascript">
        function removeAllRangesDemo() {
        if (window.getSelection){                       //check for a selection
            var selection = window.getSelection();      //get a selection object
            selection.removeAllRanges();                //remove all ranges
            }     
        }
    </script>
    </head>
    <body>
<h1>Remove all ranges example</h1>
<p>Select some text or elements on this page. When you click the button below, the selection will be cleared. </p>
<h2>h2 header</h2>
<p>Some more sample text to <strong>delete</strong>.</p>  
<input type="button" value="Remove all Ranges" onclick="removeAllRangesDemo()"   />   
    </body>
</html>

See also

IHTMLSelection::collapse