NovelProjects

Thursday, January 22, 2009

jQuery, IE and change events

I just came across something rather interesting. Apparently, IE7 has an issue with the change() function of jQuery. It works just fine in every other browser, like Firefox, but not in Internet Explorer. Here's an example of what I was using:



$('input:checkbox').change(function(){
$('.container').toggle();
});


Instead, I'm forced to use the click function and check the this.checked value to see if I should actually do any work or not. I suppose you don't necessarily need to check the this.checked value, but it's probably good practice. Here's an example of the revised version that's IE friendly:



$('input:checkbox').click(function(){
if (this.checked)
$('.container').slideDown();
else
$('.container').slideUp();
});

0 comments:

Post a Comment

Note: Only a member of this blog may post a comment.