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".
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.
I used the trigger method:
$('#selector').val(quantity).trigger("input");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With