.selection()
.selection() function can be applied to an input text field or text area elements. This function will return selected text, start and end index.
If nothing is selected, cursor position will be returned.
Returns
TypeDescription
JSONReturns the selected text, start and end index
Example 1
Select some text and click on "Show Selection" to see the selected text, starting and ending index.
JS HTML CSS
		$.domLoaded(function() {
			
			$.get("#btn1").on("click", function() {		
			
				//Get selection from text field
				var res = $.get("#inp").selection();
				
				alert("Selected Text : " + res.text 
					+ "\nStart : " + res.start
					+ "\nEnd : " + res.end);
			});		

		});							
<body>
	
	Select some text 
	<input type="text" id="inp" value="Welcome to NedilJS. Have a nice day!!" />
		
	<input type="button" id="btn1" value="Show Selection" /> 
	
</body>
	#inp {
		width : 300px;
	}
Result