17

I've got a keyup function for multiple text boxes. How do I trigger the keyup function when someone copy and past something in to the textbox?

.on("click blur keyup", ".emotion", function() {
     //match something
});
Bekki
  • 719
  • 2
  • 12
  • 20
  • 4
    DOWN-VOTERS: Please leave a comment as to why my question was down-voted. that helps. thanks. – Bekki May 19 '15 at 12:26
  • There is a paste event available in jQuery: http://stackoverflow.com/questions/11605415/jquery-bind-to-paste-event-how-to-get-the-content-of-the-paste – Thomas Theunen May 19 '15 at 12:26

3 Answers3

29

Switch the event keyup for input, which will trigger whenever something is inputted into the field, even if text is being pasted (both by pressing CTRL + V or right mouse button » Paste.

.on('input', '.emotion', function() {   
    // Do your stuff.
});
mathielo
  • 6,725
  • 7
  • 50
  • 63
4

This will do what you want:

$("#editor").on('paste', function(e) {
  $(e.target).keyup();
});

$("#editor").on('keyup', function(e) {
  alert('up');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="editor">
Thomas Theunen
  • 1,244
  • 9
  • 13
2

Use the paste event. As far as I've tested it works for Ctrl+V pasting, and right-click>Paste pasting.

Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
Bfcm
  • 2,686
  • 2
  • 27
  • 34