Tuesday, February 24, 2026
HomeLanguagesJavascriptHTML DOM selection.type property

HTML DOM selection.type property

The type property returns a String which describes the type of current selection. This is a read-only property.

Syntax:

selection.type

Return Value: String describing the type of the selection. Possible return values are:

  • None: No selection has currently been made.
  • Caret: Only Clicked but not selected. The selection is collapsed, the caret is placed on some text, but no range has been selected.
  • Range: Some range on which the text has been selected.

Example: In this example, the getSelection() method is used to get the selected text, and the type property is used to get the type of selection.

HTML




<!DOCTYPE html>
<html>
 
<head>
    <title>
          HTML DOM selection type property
      </title>
</head>
 
<body>
    <h1>neveropen</h1>
    <p>
          select some text and see its type in console
      </p>
 
    <script>
       let selection;
        document.onselectionchange = function () {
            selection = document.getSelection();
            console.log(selection)
            console.log(selection.type);
        };
    </script>
   
</body>
 
</html>


Output: In the console, types of selections can be seen on every change of selection.

Supported Browsers:

  • Google Chrome
  • Edge
  • Firefox
  • Opera
  • Safari
  • Internet Explorer
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

1 COMMENT

Most Popular

Dominic
32506 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6882 POSTS0 COMMENTS
Nicole Veronica
12005 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12099 POSTS0 COMMENTS
Shaida Kate Naidoo
7011 POSTS0 COMMENTS
Ted Musemwa
7255 POSTS0 COMMENTS
Thapelo Manthata
6967 POSTS0 COMMENTS
Umr Jansen
6956 POSTS0 COMMENTS