removeAllRanges
Summary
Removes all ranges from a selection.
Method of dom/Selectiondom/Selection
Syntax
var result = selObj.removeAllRanges();
Return Value
Returns an object of type NumberNumber
Type: HRESULT
If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.
Examples
This example uses 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>
Notes
Remarks
removeAllRanges can remove invisible carets or insertion points that result when the Collapse method is applied to a selection.
Syntax
selObj.removeAllRanges();
Standards information
- HTML5 A vocabulary and associated APIs for HTML and XHTML, Section 7.6.1
Attributions
Mozilla Developer Network : [Selection.removeAllRanges Article]
Microsoft Developer Network: [removeAllRanges Method Article]