Files
30-seconds-of-code/snippets/getSelectedText.md
2020-09-15 21:52:00 +03:00

17 lines
314 B
Markdown

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