jQuery paste event not working [Solved]

jQuery paste event not working as expected? Check input textbox working demo onpaste fire event in mobile (android, ios), desktop when user paste text in it.

Facing problem with jQuery bind paste event and not fire event when user paste text in input textbox.

Here is best solution for fire onpaste event for all the time in all devices like mobile, desktop. It also works in android, ios devices too. If you have dynamic script generated input in page, below solution will also work for it.

jQuery paste event not working [Solved]
jQuery paste event not working [Solved]

Given solution is for combine event for change, paste and cut. It works for all.

Sometime paste event not work with single event bind, like:

$('body').on('paste', 'INPUT_SELECTOR', function(){
    alert('not working here');
});

So now what to do for make jQuery paste event working? Solution is simple just bind more event with your code and that is “input”.

jQuery paste event not working – Solution

INPUT_SELECTOR = jQuery attribute selector or basic selector for input field.

$('body').on('input', 'INPUT_SELECTOR', function(){
    alert('not working here');
});

jQuery paste event working demo example

Now check below working example for jQuery paste event. For test just copy some text and paste it in below textbox. In paste event alert message added, so when you paste text, alert will display with message “Working!”

Note below solution handle event like change, so it work for all below cases.

  • change
  • paste
  • cut


If you use common event handler by giving same class to multiple input. above code will work for all input at the same time.

Here jQuery on function used for bind input event with textbox. It will work for both normal element and dynamic input element.

Sample alert displayed when jQuery paste event fire, you can change it with your process, like making Ajax call, validate input value etc.,

Conclusion

Given solution is tested and worked for my case. Hope it also useful for you and time saving. If you have other solution for jQuery paste event, always welcome to share it here, using comment section. Also if above solution not working for your case, you can share your code issue here for best solution.

If you like and found above solution helpful, you definitely like to check more jQuery article list.