Posts Learn Components Snippets Categories Tags Tools About

How to Get the User Selection Text on a Web Page

Learn how to get the user selection text on a web page the easy way

Created on Jun 28, 2022


If you want to get the text that a user selects or highlights on a web page, there is a useful one-liner for that and it's making use of the "window.getSelection" way.
const getSelectedText = () => window.getSelection().toString();


If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️