Files
30-seconds-of-code/snippets/getSelectedText.md
2022-06-08 09:34:23 +03:00

453 B

title, tags, expertise, author, cover, firstSeen, lastUpdated
title tags expertise author cover firstSeen lastUpdated
Get selected text browser beginner chalarangelo blog_images/white-tablet-2.jpg 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'