Skip to content

Instantly share code, notes, and snippets.

@cuheguevara
Created January 25, 2013 08:37
Show Gist options
  • Save cuheguevara/4632835 to your computer and use it in GitHub Desktop.
Save cuheguevara/4632835 to your computer and use it in GitHub Desktop.
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script language=javascript>
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
</script>
<input type="text" value="Some text" id="txtInput" />
<div></div>
<script>
$("#txtInput").bind("mouseup", function(){
$("div").text( getSelectionText() );
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment