alert() selected copy

by Susan Delgado

HTML

<p class="selectable">Select to show selected text in an alert window.</p>

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;
}
$(document).ready(function (){
   $('.selectable').mouseup(function (e){
       alert(getSelectionText())
   })
});