Get the text of the selection
suggest changelet sel = document.getSelection();
let text = sel.toString();
console.log(text); // logs what the user selected
Alternatively, since the toString
member function is called automatically by some functions when converting the object to a string, you don’t always have to call it yourself.
console.log(document.getSelection());
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents