How to check the increase/decrease of letter input in pasting clipboard in jQuery

I can use the keyup() function to check that my user has written something in input.
But what do I do when something pastes there?(Using the mouse, not the keyboard!)

$("#myInput").keyup(function(){
  console.log("increase or decrease now!");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input id="myInput" />

>Solution :

The "keyup" event only fires after a (finished) keyboard input, which means it does not fire when you paste something with your mouse. You could instead use the "paste" event, which only fires after you paste something into the input field. But you can combine "keyup" and "paste" like this:

$("#myInput").on("keyup paste", function(){
  console.log("increase or decrease now!");
});

You could also think about the "change" event. This only fires after the input field was changed and loses focus. So, you could actually replace keyup paste by change or combine all of the three to be sure it is fired no matter how the user changes the input field by using keyup paste change.

Leave a Reply