views:

34

answers:

2

Hi!

I have a page with a checkbox that is set to checked when the page is loaded. If/when the checkbox is unchecked I need to run a function. The following code works fine in all browsers with the exception of IE. In versions 7 and 8(haven't even tested 6) it works but you are required to uncheck it, check it, then on the second uncheck it executes the function. The jQuery documentation states: "As of jQuery 1.4 the change event now bubbles, and works identically to all other browsers, in Internet Explorer"... but it doesn't seem to work. Any ideas?

The code:

$('#checkbox').change(function() {
  // do something
});
+1  A: 

If you want to stop event bubbling, use

$('#checkbox').change(function(event) { 
    event.stopPropagation();
    // do something 
});

Perhaps you could also do something like

if ($.browser.msie) {
    $('#checkbox').click(function() { // assuming this will be fired for keyboard as well

        $(this).change();
    });

};

This may force the event.

alex
+1  A: 

Upgrade to jQuery 1.4.2+ to resolve this. The 1.4.2 release included several changes/fixes for events.

This change event, change bubbling in IE (big one for many people), and lots more was fixed in that release, upgrading will resolve your issue :)

Nick Craver
@mike If this worked for you, please accept it :)
alex