Hi,

> Is there a difference in speed?  Is one better than the other in
> another way?

Faster still, use 'this'.  As of version 1.6, Prototype ensures that
the event handler function is called such that 'this' refers to the
element that you hooked the event handler to[1]:

$('element_id').observe('click, function(event) {

    // Here, 'this' refers to the element
});

Of course, if you use Function#bind[2] to do something else with
'this', you'll have to use something else, but many times 'this' is
just what you need.

Finally, note that Event#findElement[3] is now preferred over
Event#element, which will be deprecated in later versions.  (Or so
Tobie tells me.)

[1] http://prototypejs.org/api/event/observe
[2] http://prototypejs.org/api/function/bind
[3] http://prototypejs.org/api/event/findElement

HTH,
--
T.J. Crowder
tj / crowder software / com
Independent Software Engineer, consulting services available

On Mar 26, 9:54 pm, Dave L <dly...@gmail.com> wrote:
> Im wondering, what is the difference between the following:
>
> $('object_id').observe('click', function(event){
>     element = event.element()
>
> }
>
> VERSUS
>
> $('object_id').observe('click', function(event){
>     element = $('object_id)
>
> }
>
> Is there a difference in speed?  Is one better than the other in
> another way?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to 
prototype-scriptaculous+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to