Categories
JavaScript Answers

How to clear text selection with JavaScript?

Spread the love

Sometimes, we want to clear text selection with JavaScript.

In this article, we’ll look at how to clear text selection with JavaScript.

How to clear text selection with JavaScript?

To clear text selection with JavaScript, we can use the empty method.

For instance, we write

window.getSelection().empty();

to call getSelection to get the select text in an object.

Then we call empty to clear the selection.

Conclusion

To clear text selection with JavaScript, we can use the empty method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *