Get selected text
Gets the currently selected text.
- Use
Window.getSelection()
andSelection.toString()
to get the currently selected text.
const getSelectedText = () => window.getSelection().toString(); getSelectedText(); // 'Lorem ipsum'
Gets the currently selected text.
Window.getSelection()
and Selection.toString()
to get the currently selected text.const getSelectedText = () => window.getSelection().toString(); getSelectedText(); // 'Lorem ipsum'
Learn a simple way to get the browser's current URL in JavaScript.
Calculate the coordinates of the current scroll position in the browser window using JavaScript.
Here's a quick and easy way to select the currently focused DOM element in JavaScript.
Learn how to programmatically copy text to clipboard with a few lines of JavaScript and level up your web development skills.