Skip to content

Latest commit

 

History

History
16 lines (12 loc) · 314 Bytes

getSelectedText.md

File metadata and controls

16 lines (12 loc) · 314 Bytes
title tags
getSelectedText
browser,beginner

Get the currently selected text.

  • Use window.getSelection() and Selection.prototype.toString() to get the currently selected text.
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'