Skip to content

Instantly share code, notes, and snippets.

@cmdoptesc
Last active December 20, 2015 13:19
Show Gist options
  • Save cmdoptesc/6137770 to your computer and use it in GitHub Desktop.
Save cmdoptesc/6137770 to your computer and use it in GitHub Desktop.
getSelectedText
var getSelectedText = function() {
var txt = "";
if (window.getSelection) {
txt = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
txt = document.selection.createRange().text;
}
return txt;
};
$(document).mouseup(function(){
console.log(getSelectedText());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment