Windows apps
Collapse the table of content
Expand the table of content
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

isCollapsed property

Retrieves whether a selection is collapsed or empty.

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




p = object.isCollapsed


Property values

Type: Boolean

One of the following values:

false (false)

The selection is not collapsed.

true (true)

The selection is collapsed or empty.

Standards information


A collapsed selection has its start and end points set to the same value, which renders it empty.


This example uses isCollapsed to see whether a selection is empty or not. If the selection is not empty, the selected text is displayed.

<!DOCTYPE html>

    <meta http-equiv="X-UA-Compatible" content="IE=9" />  <!-- Only works in Internet Explorer 9 -->     
    <!-- This example shows the character offset from anchor node of your selection. -->
    <title>isCollapsed Example</title>        
    <script type="text/javascript">         
      function testCollapsed () {
        if (window.getSelection) {      
          var oSel = window.getSelection();
          var oDisplayBox = document.getElementById('displayBox');
          if (oSel.isCollapsed) {
            oDisplayBox.innerHTML = "<p>Nothing is selected!</p>";
          else {
            oDisplayBox.innerHTML = "<p>The text of the selection:\n" + oSel.toString() + "</p>";

      Click the button below to get the text content. 
      Use the mouse to select some text within this field. 
      Then, click the button again to see if the selection is collapsed.
    <input type="button" value="Is it collapsed" onclick="testCollapsed()" />   
    <div id="displayBox"></div>

See also




© 2017 Microsoft