safari 3.1 breaks your app

Courtenay : March 21st, 2008

If you're doing anything like

$('foo').getElementsByClassName("monkey").each(Element.hide)

Safari 3.1 out this week breaks this, because it now natively implements getElementsByClassName.

So, pending a fix from the Prototype guys, one of whom has a desk next to mine, be aware that your apps may be broken for your Safari users.

You can easily change that code to

$$("#foo .monkey").each(Element.hide)

9 Responses to “safari 3.1 breaks your app”

  1. Bruno Miranda Says:

    Thank you for the heads up!

  2. Cezary Says:

    The most elegant would be probably: $$('#foo .monkey').invoke('hide')

  3. Bill Burcham Says:

    Yep. Mine's broke. Noticed some drag&drop not working in one of my client's apps. From a casual glance at prototype.js it looks like it's trying to handle browsers that support the method natively. On line 2164 of 1.6.0_rc0 I see a test for presence of the native method on document. Well, that's what I get for "casually" glancing at prototype.

  4. Steve Upton Says:

    The $$ selector function is great but it doesn't replace getElementsByClassName's optional parentElement parameter - which I use all the time. Or does it?

    I saw in Prototype that getElementsByClassName is marked as deprecated. It seems like I must be missing something..

    Thanks for the heads up though. I was certainly wondering what was going on.

  5. Steve Upton Says:

    The $$ selector function is great but it doesn't replace getElementsByClassName's optional parentElement parameter - which I use all the time. Or does it?

    I saw in Prototype that getElementsByClassName is marked as deprecated. It seems like I must be missing something..

    Thanks for the heads up though. I was certainly wondering what was going on.

  6. Jerry Richardson Says:

    Thanks! - I switched to using $$ and it fixed it right up for me.

  7. Andrew Dupont Says:

    This'll do what you want.

    http://prototypejs.org/api/element/select

  8. AkitaOnRails Says:

    Thanks, this is exactly where I was stuck at: debugging active_scaffold.js in the exact line of getElementsByClassName where ir registers the close handler for the cancel links.

    This bug shows up at Firefox 3 as well, it seems. If you use Active Scaffold, take a look at this thread for a solution: http://groups.google.com/group/activescaffold/browse_thread/thread/d37afa3f2ac687f2

  9. Steve Upton Says:

    yep, .select did it.

    For the record, I changed:

    elms = document.getElementsByClassName('classname',parentElement);

    into

    elms = $(parentElement).select('.classname');

    The $ is handy when the element isn't yet extended OR is an id and don't forget to put the '.' in front of the class name to make it a class selector.

    Thanks for your help. (PS, any CSS you can add to the "Submit Comment" button on this page that would give click feedback would be a good idea... sorry for the double post earlier)

Sorry, comments are closed for this article.