I use the following snippet to get the text of a selected/marked sentence How can I extend the selection to get the sentence with whole words? For example if the user starts and ends the selection within the words. Thank you for your tips.
JS
function selectHTML() {
try {
if (window.ActiveXObject) {
var c = document.selection.createRange();
return c.htmlText;
}
var nNd = document.createElement("span");
$('#helperDiv').val(nNd);
var w = getSelection().getRangeAt(0);
w.surroundContents(nNd);
return nNd.innerHTML;
} catch (e) {
if (window.ActiveXObject) {
return document.selection.createRange();
} else {
return getSelection();
}
}
}