Issue with Enumerable#invoke and IE

1 view
Skip to first unread message

Michael Irwin

unread,
Aug 10, 2008, 11:49:47 PM8/10/08
to Prototype & script.aculo.us
This code works fine in Safari and Firefox, but throws an error in IE7
(not sure about IE6):

$$('.focus').invoke('focus');

This works in all of the aforementioned browsers:

$$('.focus').each(function(el) {
el.focus();
});

Any ideas on why the first snippet doesn't work in IE7?

T.J. Crowder

unread,
Aug 11, 2008, 12:16:26 AM8/11/08
to Prototype & script.aculo.us
> This code works fine in Safari and Firefox, but throws an error in IE7

*What* error?
--
T.J. Crowder
tj / crowder software / com

kangax

unread,
Aug 11, 2008, 12:18:35 AM8/11/08
to Prototype & script.aculo.us
What are the elements returned by "$$('.focus')" ?

--
kangax

Justin Perkins

unread,
Aug 11, 2008, 1:45:17 AM8/11/08
to prototype-s...@googlegroups.com
To add to the questions, how/why would you focus more than one element?

-justin

Michael Irwin

unread,
Aug 11, 2008, 12:52:33 AM8/11/08
to Prototype & script.aculo.us
Sorry... I forgot to include the error. The IE error is "Object
doesn’t support this property or method", and it's just returning an
input.

Michael Irwin

unread,
Aug 11, 2008, 1:52:44 AM8/11/08
to Prototype & script.aculo.us
It's not that I'm trying to focus more than one element, it's just
that the element's ID is already set dynamically (using Rails), so I'm
just adding a class name of "focus" as an easy, generic way to access
the element. There's never more than one '.focus' per page.

T.J. Crowder

unread,
Aug 11, 2008, 3:35:59 AM8/11/08
to Prototype & script.aculo.us
Hi,

> it's just returning an input

I don't suppose there are any hidden inputs with that class? (Maybe
IE doesn't like focussing hidden inputs.) But that wouldn't explain
why the each() version works when the invoke() version doesn't.

> It's not that I'm trying to focus more than one element, it's just
> that the element's ID is already set dynamically (using Rails), so I'm
> just adding a class name of "focus" as an easy, generic way to access
> the element. There's never more than one '.focus' per page.

In that case, although I'm still curious why IE has an issue with
invoke(), you may be better off with:

$$('.focus').first().focus();

...as that's at least clearer to subsequent authors that you're not
trying to enter a group of input elements in some kind of focus
superposition. :-)
--
T.J. Crowder
tj / crowder software / com

Michael Irwin

unread,
Aug 11, 2008, 3:50:06 AM8/11/08
to Prototype & script.aculo.us
No hidden elements with the same class name. I didn't think to try
the first() way you mentioned, but just did and it works fine. It's
just odd that IE7 can't handle the invoke() way, though. Oh well,
such is life with IE, I guess.

Thanks,

Mike Irwin

T.J. Crowder

unread,
Aug 11, 2008, 5:34:19 AM8/11/08
to Prototype & script.aculo.us
> ...It's
> just odd that IE7 can't handle the invoke() way, though...

It is indeed. Can you put together a minimal page that demonstrates
this behavior and paste it over on http://pastie.org? It may be a
subtle bug in invoke() on IE7...

-- T.J. :-)

kangax

unread,
Aug 11, 2008, 7:31:49 AM8/11/08
to Prototype & script.aculo.us
On Aug 11, 5:34 am, "T.J. Crowder" <t...@crowdersoftware.com> wrote:
> > ...It's
> > just odd that IE7 can't handle the invoke() way, though...
>
> It is indeed.  Can you put together a minimal page that demonstrates
> this behavior and paste it over onhttp://pastie.org? It may be a
> subtle bug in invoke() on IE7...

Don't you just love IE's host objects : )
#invoke calls apply on a method for each element, but "focus.apply" is
undefined in IE, so the error is thrown.

--
kangax
Reply all
Reply to author
Forward
0 new messages