To get the text selection in Javascript you can use the following snippet.

Sample Javascript

function GetTextSelection() {
	return (!!document.getSelection) ? document.getSelection() :
	       (!!window.getSelection)   ? window.getSelection() :
	       document.selection.createRange().text;
}

2 thought on “How to get the text selection in Javascript”

Leave a Reply