Files
30-seconds-of-code/snippets/get-selected-text.md
Angelos Chalaris 61200d90c4 Kebab file names
2023-04-27 21:58:35 +03:00

417 B

title, tags, author, cover, firstSeen, lastUpdated
title tags author cover firstSeen lastUpdated
Get selected text browser chalarangelo white-tablet-2 2020-08-07T15:34:53+03:00 2020-10-19T22:49:51+03:00

Gets the currently selected text.

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