Nest all content into snippets
This commit is contained in:
21
snippets/js/s/get-selected-text.md
Normal file
21
snippets/js/s/get-selected-text.md
Normal file
@ -0,0 +1,21 @@
|
||||
---
|
||||
title: Get selected text
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [browser]
|
||||
author: chalarangelo
|
||||
cover: white-tablet-2
|
||||
dateModified: 2020-10-19T22:49:51+03:00
|
||||
---
|
||||
|
||||
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'
|
||||
```
|
||||
Reference in New Issue
Block a user