Getting jQuery to recognise .change() in IE Getting jQuery to recognise .change() in IE jquery jquery

Getting jQuery to recognise .change() in IE


The problem with using the click event instead of change is you get the event if the same radio box is selected (i.e. hasn't actually changed). This can be filtered out if you check that the new value is different than the old. I find this a little annoying.

If you use the change event, you may notice that it will recognize the change after you click on any other element in IE. If you call blur() in the click event, it'll cause the change event to fire (only if the radio boxes actually have a changed).

Here's how I'm doing it:

// This is the hack for IEif ($.browser.msie) {  $("#viewByOrg").click(function() {    this.blur();    this.focus();  });}$("#viewByOrg").change(function() {  // Do stuff here});

Now you can use the change event like normal.

Edit: Added a call to focus() to prevent accessibility issues (see Bobby's comment below).


Have you tried IE's onpropertychange event? I dont know if it makes a difference but it's probably worth a try. IE does not trigger the change event when values are updated via JS code but perhaps onpropertychange would work in this instance.

$("#viewByOrg").bind($.browser.msie? 'propertychange': 'change', function(e) {  e.preventDefault(); // Your code here });