Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger the keyup function when someone copy and paste

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
});
like image 993
Bekki Avatar asked May 19 '15 12:05

Bekki


People also ask

Why is Keyup not working?

keyup / keydown seem to only work on elements that are present at document. ready . If you are triggering your event from elements that were altered or injected post pageload, these events will not fire.

What does Keyup mean in Javascript?

The keyup event is fired when a key is released. The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .

What is Keyup function in jQuery?

The keyup() is an inbuilt method in jQuery which is used to trigger the keyup event whenever User releases a key from the keyboard. So, Using keyup() method we can detect if any key is released from the keyboard. Syntax: $(selector).keyup(function) Here selector is the selected element.


2 Answers

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.
});
like image 156
mathielo Avatar answered Sep 20 '22 14:09

mathielo


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">
like image 22
Thomas Theunen Avatar answered Sep 21 '22 14:09

Thomas Theunen