Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery how to get the pasted content

Tags:

jquery

paste

I have a little trouble catching a pasted text into my input:

 <input type="text" id="myid" val="default">  $('#myid').on('paste',function(){         console.log($('#myid').val());  });   

console.log shows:

default 

How I catch the pasted text and get ready to use?

like image 893
greenbandit Avatar asked Feb 29 '12 06:02

greenbandit


People also ask

How to get paste value in jQuery?

jQuery(document). ready(function($){ $(". myinput"). on("paste",function(){ var _this=$(this); // we can access input value on paste after some time setTimeout(function(){ // access element value console.

How do I paste Javascript?

Tip: There are three ways to paste some content in an element: Press CTRL + V. Select "Paste" from the Edit menu in your browser. Right click to display the context menu and select the "Paste" command.


1 Answers

The accepted answer is actually hacky and ugly, seems to be suggested quite often for the paste event on stackoverflow. I think a better way to do it is this

$('#someInput').bind('paste', function(e) {     var data = e.originalEvent.clipboardData.getData('Text');     //IE9 Equivalent ==> window.clipboardData.getData("Text");    }); 
like image 171
cateyes Avatar answered Sep 21 '22 21:09

cateyes