jQuery Differences in Firefox & Safari

Posted by bob Thu, 05 Jun 2008 01:51:00 GMT

I've had to do a fair amount of view layer work recently using the jQuery Javascript library, which is really a brilliant piece of work.  However, I experienced a few difficulties in achieving consistent cross browser behavior, specifically within Firefox (2.0.x) and Safari (3.1.1).  IE has been purposefully left alone for now.  Nothing too egregious, but potentially time consuming to resolve...especially for people with rusty Javascript skills.

The attr function

The attr function allows for quickly updating a set of matched DOM elements.  The following was my first attempt - it works without issue in Firefox:

jQuery("a[@id ^= '" + updateParentLink + "']")
   .attr({class: "thickbox btn edit",title: "Edit Details"});

Running this in Safari caused a general and unfortunate Javascript parse error.  Through trial and error, I discovered that Safari apparently does not like style (class) attributes being manipulated using the attr function.  The fact that it causes a parse error is still not really clear to me.  I got around this by simply using the jQuery functions addClass and removeClass, and only used attr to change the 'title' attribute.

The post function

I'm using the jQuery post (ajax) function for quick authentication within a view.  The response of the POST operation is obviously important here, and again I was seeing different behavior in Safari compared to Firefox.  The callback function that handles the response expects a (valid) URI to initiate another request; in Safari, the response URI was not being resolved right.  The problem was that the URI in the response had an encoded line break character - originating from the server page responsible for passing back the URI.  Firefox knew to remove it, Safari did not.  

 

Comments

Leave a comment

Comments