const getSelectedText = () => window.getSelection().toString(); console.log(getSelectedText());
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
•83 views
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.
new
If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️
Load comments for How to Get the User Selection Text on a Web Page
new
PostSrc Code Components
Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.
View Components