Files
30-seconds-of-code/javascript/snippets/get-selected-text.md
2023-05-01 22:35:56 +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'