DEV Community

Cover image for How to get selected text if Ctrl + Enter is pressed?
101samovar
101samovar

Posted on

How to get selected text if Ctrl + Enter is pressed?

There is some site.
There is a text on that site.
To get selected text we need the document object and the getSelection method.
The getSelection method returns a Selection object.
We need toString method of the Selection object to get the selected text.
To check the Ctrl + Enter combination is pressed we need to add an event listener
and to test key and ctrlKey properties of the event object.
That’s all.
Let’s open the site, select a text part and press ctrl enter.
We have got the selected text.

our channel:
https://www.youtube.com/c/Samovar101

Discussion (0)