Created
January 25, 2013 08:37
-
-
Save cuheguevara/4632835 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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