jQuery(function() {
// Bind the click handler of some button on your page
jQuery('#someButton').click(function(evt) {
// Insert the selected text into a given textarea
var textarea = jQuery('textarea#someTextArea');
textarea.val(textarea.val() + getSelectedText());
evt.preventDefault();
});
});
// Get user selection text on page
function getSelectedText() {
if (window.getSelection) {
return window.getSelection();
}
else if (document.selection) {
return document.selection.createRange().text;
}
return '';
}