Files
30-seconds-of-code/snippets/getSelectedText.md
Isabelle Viktoria Maciohsek 27c168ce55 Bake date into snippets
2021-06-13 13:55:00 +03:00

381 B

title, tags, firstSeen, lastUpdated
title tags firstSeen lastUpdated
getSelectedText browser,beginner 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'