Files
30-seconds-of-code/snippets/getSelectedText.md
Isabelle Viktoria Maciohsek 920a0c390b Update snippet descriptions
2020-10-19 22:49:51 +03:00

17 lines
305 B
Markdown

---
title: getSelectedText
tags: browser,beginner
---
Gets the currently selected text.
- Use `Window.getSelection()` and `Selection.toString()` to get the currently selected text.
```js
const getSelectedText = () => window.getSelection().toString();
```
```js
getSelectedText(); // 'Lorem ipsum'
```