Get the text of the selection

suggest change
let 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());

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents