Get selected text
JavaScript, Browser · Oct 19, 2020

Gets the currently selected text.
- Use
Window.getSelection()
andSelection.toString()
to get the currently selected text.
const getSelectedText = () => window.getSelection().toString();
getSelectedText(); // 'Lorem ipsum'