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?
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.
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.
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"); });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With