JavaScript document.getSelection() Method
You are Here:
JavaScript document.getSelection() Method
The document.getSelection()
method returns a selection object representing the range of text selected by the user, or the current position of the caret.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<input type="text" onselect="myFunction()" value="Select some text">
<p id="point"></p>
<script>
var x = document.getElementById("point");
function myFunction(){
var selObj = document.getSelection();
x.innerHTML = "You Selected: <strong>"+ selObj+"</strong>";
}
</script>
</body>
</html>
Syntax
document.getSelection()
Return Values
Value | Explanation |
---|---|
Object | Returns a selection object. |
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.