I have to save highlighted text from textarea into database on click event how can i do it. I found some code from so but it doesn't work for me.
$('#send').on("click", function(){
ShowSelection();
});
function ShowSelection()
{
var textComponent = $('#my-content span').val();
console.log(textComponent);
var selectedText;
if (textComponent.selectionStart !== undefined)
{// Standards Compliant Version
var startPos = textComponent.selectionStart;
var endPos = textComponent.selectionEnd;
selectedText = textComponent.value.substring(startPos, endPos);
}
else if (document.selection !== undefined)
{// IE Version
textComponent.focus();
var sel = document.selection.createRange();
selectedText = sel.text;
}
alert("You selected: " + selectedText);
}