Regarding the .trigger() method, the Event object, the which property, the JS char codes and the code below, why does the #example input don’t get the char a as auto-written value? Did I misunderstand the .trigger() method?
<input type="text" name="example" id="example" value="" />
<script>
$(function() {
var e = jQuery.Event("keydown", { which: 65 });
$("#example").focus().trigger(e);
});
</script>
The mistake you’re making is what you’re expecting the jQuery’s
triggermethod to do. If you check out the code you’ll see that what it is doing is actually executing the jQuery registered event handlers not the DOM Level 3 events. Because it’s only executing jQuery handlers you wont be causing thechangeevent which is what you need to be triggered to update the value property of the textbox.