The getSelection Method
The getSelection method creates an object
of the selected document fragment.
Syntax
getSelection();
Example
When clicking the button, we will output the selected document fragment:
<input type="button" id="button" value="output selected fragment">
let button = document.getElementById('button');
button.addEventListener('click', function() {
let str = getSelection().toString();
alert(str);
});
:
See also
-
method
createRange,
which is the document fragment object