Files
30-seconds-of-code/snippets/getSelectedText.md
2020-09-15 21:52:00 +03:00

314 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'