Programmer Question
I have been investigating event fire order between browsers, because our application is experiencing some unusual behaviour.
I have created a little test to see the order of the three events: change, keydown, and keypress.
Here is the HTML (test.html):
Results
Here is the JS (test.js):
/*
Appends event information to display table.
*/
$(document).ready(function() {
$("#TextBox").change(function() {
$("Change ").appendTo("#ResultTable");
});
$("#TextBox").keydown(function() {
$("Key down ").appendTo("#ResultTable");
});
$("#TextBox").keypress(function() {
$("Key press ").appendTo("#ResultTable");
});
$("#Button").click(function() {
$("#ResultTable").empty();
$("Results ").appendTo("#ResultTable");
});
});
When I type letter f into the textbox, then press enter, I get the following in Internet Explorer 8:
Results
- Key down
- Key press
- Change
- Key down
- Key press
But in Firefox (3.6.8), I get the following:
Results
- Key down
- Key press
- Key down
- Key press
- Change
The order of the change event is significant as we are capturing the enter key in the keydown event, but doing some validation with the change event.
I have had a look around, but haven't been able to identify where the issue is.
Is this expected behaviour?
Should all browsers fire jQuery events in a specified order?
Or should we remove all assumptions for order of event firing?
Or is there something else that is getting in the way I am not thinking about?
Find the answer here
No comments:
Post a Comment