I'm looking for a simple function (javascript / jquery) that checks whether or not ANY contents of a textarea is selected or highlighted... the function needs to return true or false.
Thanks :)
I'm looking for a simple function (javascript / jquery) that checks whether or not ANY contents of a textarea is selected or highlighted... the function needs to return true or false.
Thanks :)
Try this
function isTextSelected(input){
var startPos = input.selectionStart;
var endPos = input.selectionEnd;
var doc = document.selection;
if(doc && doc.createRange().text.length != 0){
return true;
}else if (!doc && input.value.substring(startPos,endPos).length != 0){
return true;
}
return false;
}
Usage
if(isTextSelected($('#textareaId')[0])){
//text selected
}