Jquery is awesome.

I stumbled across a bug when dealing with checkboxes and the change event with Internet Explorer.

I wanted my interface to trigger a javascript function when a checkbox was – you guessed it, checked.

Ditto if it the checkbox later was un-checked.

The following works in Firefox:

$(“#mapsearch”).change(function() { updateresults(1); return false; });

The problem in IE is that the above doesn’t work until you click somewhere else on the page ( anywhere ) … something to do with the event handler not firing because the checkbox has focus. Whatever.

I was searching the net for a fix, some people had come up with some elaborate solutions, additional functions, alternative check boxes through jquery extensions …

I wanted the simple answer, here it is one extra line:

$(“#yourdiv”).change(function() { myfunction(1); return false; });
$(“#yourdiv”).click(function() { this.blur(); });

After the checkbox looses its focus the event fires as it should and all checkboxes were once again behaving as they should.