Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to trigger an input event with jQuery?

Tags:

I want to add 'a' to the value of input when click a button

Here is my code(with jQuery 1.4.4):

$("#button").click(function(){     $("#input").trigger("focus");     var e = jQuery.Event("keypress");     e.which = '97';     $("#input").trigger(e); }) 

However, it seems only to trigger "focus" event, but failed to "keypress".

like image 888
user1990553 Avatar asked Mar 21 '13 10:03

user1990553


People also ask

What is trigger event in jQuery?

The trigger() method triggers the specified event and the default behavior of an event (like form submission) for the selected elements. This method is similar to the triggerHandler() method, except that triggerHandler() does not trigger the default behavior of the event.


1 Answers

I used the trigger method:

$('#selector').val(quantity).trigger("input"); 
like image 163
Luminita Balas Avatar answered Oct 21 '22 13:10

Luminita Balas