how to get the selected text in javascript code example
Example 1: get selected text js
// Get highlighted text this way:
window.getSelection().toString()
Example 2: get selected text input javascript
function disp() {
var text = document.getElementById("text");
var t = text.value.substr(text.selectionStart, text.selectionEnd - text.selectionStart);
alert(t);
}