Files
30-seconds-of-code/snippets/get-selected-text.md
2023-04-28 22:29:23 +03:00

397 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Get selected text snippet
browser
chalarangelo white-tablet-2 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'