asdf
Given this div, if a user were to select the word asdf
with their cursor, the the character count would be 4.
In JavaScript, how can you determine what the user has selected with their cursor; more specifically, text.
jQuery library preferred.
I've tried:
var text = document.getSelection().toString();
var length = document.getSelection().toString().length;
if (text) {
alert(text);
}
if (length) {
alert(length);
}