Get the currently selected text with JavaScript Use Window.getSelection() and Selection.toString() to get the currently selected text. const getSelectedText = () => window.getSelection().toString(); // OUTPUT getSelectedText(); // 'Lorem ipsum' Source https://www.30secondsofcode.org/js/s/get-selected-text