Ahhh, this is the life: struggling for days with some obscure IE bug.
I have an onchange attribute with a jQuery AJAX call on a HTML dropdown that gives strange errors. But only in IE (8, didn't try it in other versions). When replacing the AJAX call with an alert, like so:
it becomes clear that the onchange is triggered twice. This was also confirmed in the IE Developer Tools window, but I can't use that to debug further.
Apparently, after this .change binding is done, IE8 triggers the HTML onchange, twice.
My first approach to solve this generically is to automatically convert HTML onchange attributes to jQuery .change bindings. I tried to "copy" the onchange from the HTML attribute to jQuery using:
Unfortunately this gave some unexpected behaviour in IE7, because where dropdown.attr("change") returns this in IE7:
In FF en IE8 it returns:
In other words: don't mix the HTML onchange attribute and jQuery onchange binding (unless you don't care to support IE).
Now I've fully migrated all onchange behaviour to multiple jQuery binds, only leaving a CSS class (e.g. 'alert') in the HTML, and then tracking dropdowns with that class:
I am using a namespaced bind (the '.alert' suffix to the 'change' string in the more generic .bind function, instead of using just .change). This makes it possible to just unbind this onchange function, and leave other onchange functions bound. This is required, because I also do an unbind right before the bind. This is to prevent multiple binds after the AJAX request.