ASU Web Community

A functional difference

Wednesday, November 7th, 2007 - 12:31 am
  • jrbeeman
  • jrbeeman's picture

This isn't directly related to Drupal, per se, but it happened while I was writing a Drupal module so I'll post it up here as a way of personal note taking and maybe one day helping out someone who experiences this problem...

So, apparently IE wigs out occasionally with attaching newly defined functions to events via jQuery. Take the following code, for example:

$('#my-textfield').focus( function() { Drupal.do.something(); });

The code above follows examples on the jQuery docs site, other code in Drupal (see autocomplete.js, for example), and is fairly standard code for jQuery stuff.

The situation I just spent 2 hours trying to solve involved:

  1. doing the above
  2. calling $('#my-textfield').unbind();(for various module-related reasons too boring to get into here)
  3. calling the above again, to reestablish the event binding

This worked perfectly fine in Firefox, but caused unresponsive script errors in IE 6 and 7. What was the fix? A simple matter of semantics. Bind directly to the function name, and everything is peachy-keen:

$('#my-textfield').focus( Drupal.do.something );

Maybe this is fixed in newer versions of jQuery (Drupal 5.2 runs on jQuery 1.0.1, I believe), but regardless it's far from something that should be breaking Internet Explorer.

Wednesday, December 5th, 2007 - 1:31 pm
  • ngudmuns
  • ngudmuns's picture

Thanks Jeff.  I wonder how many folks on the forums use jQuery to extend their Drupal sites. If it is being used, it'd be great to hear more about it. If not, maybe we can teach jQuery somehow in a tutorial for the ASU community.