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.