How to trigger an input event with jQuery?
jquery, triggers
Solution
like this?? Sorry, I'm confused with your writings..
$("#button").click(function(){
$("#input").trigger("keypress") // you can trigger keypress like this if you need to..
.val(function(i,val){return val + 'a';});
});
reference: .val(function(index, value));
Problem
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".