JavaScript
Article

jQuery Capture Copy, Paste and Cut Events

By Sam Deering

This is how you can capture if someone has copied, cut or pasted into a input text area.

Demo

Copy, cut or paste text from/to the text area below.


The Code

(function($)
{
    $(document).ready(function() {

        $("#textinput").bind({
            copy : function(){
                $('#eventresult').text('copy behaviour detected!');
            },
            paste : function(){
                $('#eventresult').text('paste behaviour detected!');
            },
            cut : function(){
                $('#eventresult').text('cut behaviour detected!');
            }
        });

    });
})(jQuery);
  • mahesh

    ur post is nice….but i need the code how to cut,copy and paste …….i am designing my own right click context menu in that i would like to put these 3 things …..can u please send the code to mail …..koritala.mahesh@gmail.com

  • Vinicius

    Ok, but does the input event solve the same problem?

    Code:
    $(“#textinput”).on(‘input’, function(){ $(‘#eventresult’).text(‘INPUT behaviour detected!’); });

  • Soumik

    Well its a nice code to track copy event , can u tell me what would be the code to trigger copy functionaly of a component when used in mobile

Recommended

Learn Coding Online
Learn Web Development

Start learning web development and design for free with SitePoint Premium!

Get the latest in JavaScript, once a week, for free.