On 14 sep, 03:08, Roland <[EMAIL PROTECTED]> wrote:
> Hi there,
>
> Events can be attached multiple times to the same element.. is there a
> way to prevent this?
>
> Something like ...
>
> if(!$(el).hasEventAttached()) Event.observe($(el), 'click',
> function());
>

Personally, I fail to see the real benefit of this, I mean :

1. simply having such function parameterless would be very confusing
if you wanted to add an onclick event to an element that already has
(for example) an onmouseover event attached. I might be mistaking, but
with the suggested line, the function would return true if any event
is attached to the element.

2. if the function would have it's first parameter (may be optional)
specifiying what event to look for on the selected element, how would
the function tell that the event function you want to hook is hooked
to the element already ? As elements may have multiple onclick events
(for example), the function would return true if any onclick event had
been set for that element, and not necessarily the one you intended to
set.

3. if the function would have also a second parameter (may be
optional) specifying the actual event function that you want to test
if it already been set, the whole process of calling this function
would imply an additional conditionnal statement in your script as
this test is already been made (sort of) in the observe() function
already (v 1.6.0)

If you find that same events are attached multiple times on the same
element, please provide a working case to demonstrate the problem. It
is in my opinion that Event.observe should check for this kind of
potential problem, so Prototype should not require that kind of
feature.

Cheers.
yanick


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to