Categories
JavaScript Answers

How to get selected text in JavaScript?

Spread the love

Sometimes, we want to get selected text in JavaScript.

In this article, we’ll look at how to get selected text in JavaScript.

How to get selected text in JavaScript?

To get selected text in JavaScript, we can use the document.selection.createRange or window.getSelection methods.

For instance, we write

document.selection.createRange().text

or

window.getSelection()

to return the currently selected text.

Conclusion

To get selected text in JavaScript, we can use the document.selection.createRange or window.getSelection methods.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.