Files
30-seconds-of-code/snippets/getSelectedText.md
Angelos Chalaris 4cf93754d2 Add getSelectedText
2020-08-07 15:34:53 +03:00

312 B

title, tags
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'