Files
30-seconds-of-code/snippets/js/s/get-selected-text.md
2023-05-07 16:07:29 +03:00

418 B

title, type, language, tags, author, cover, dateModified
title type language tags author cover dateModified
Get selected text snippet javascript
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'