Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invoke a function after right click paste in jQuery

I know we can use bind paste event as below:

$('#id').bind('paste', function(e) { 
    alert('pasting!') 
});

But the problem is, that it will call before the pasted text paste. I want a function to be triggered after the right click -> paste text pasted on the input field, so that I can access the pasted value inside the event handler function.

.change() event also doesn't help. Currently I use .keyup() event, because I need to show the remaining characters count while typing in that input field.

like image 820
FrankD Avatar asked Aug 27 '12 17:08

FrankD


2 Answers

Kind of a hack, but:

$("#id").bind('paste', function(e) {
        var ctl = $(this);
        setTimeout(function() {
            //Do whatever you want to $(ctl) here....
        }, 100);
});
like image 180
Jaime Torres Avatar answered Nov 01 '22 20:11

Jaime Torres


Why not use the "input" event?

$("#id").bind('input', function(e) {
    var $this = $(this);
    console.log($this.val());
});
like image 43
JChen___ Avatar answered Nov 01 '22 21:11

JChen___