Get selected text as string

By Hunter Becton on August 4, 2022

const getSelectedText = () => window.getSelection().toString();

How to use

This code snippet is useful for building a toolbox that can be used to share bits of an article to social or to save as a note in your database.