Get Selection

by shapeshifta

HTML

<p>lorem ipsum <br /> lorem ipsum und so weiter  :)</p>
<input value="bla bla" />
<span id="selection"></span>
<span id="cutCopyPaste"></span>

CSS

span { display:block }
#selection { color:#f00 }
#cutCopyPaste { color:#00f }

JavaScript

$('p, input').bind({
    copy: function() {
        alert('copy detected!');
    },
    paste: function() {
        alert('paste detected!');
    },
    cut: function() {
        alert('cut detected!');
    }
});


/* kürzer:
$("p").bind('cut copy paste', function(e) {
    alert(e.type + ' text!');
}); */