need help with event.observe

0 views
Skip to first unread message

ecb

unread,
Jul 22, 2008, 10:00:24 PM7/22/08
to Ruby on Rails: Spinoffs
Hi,

I need help with the following problem.

<code>
var xspanid = .. whatever ...
Event.observe(xspanid, "click",
this.deleteitem.bindAsEventListener(this, xspanid));
</code>

the code above works (I've included two lines that I think are
equivalent and both work the same, just . The problem I'm having is
that deleteitem is only bound to the most recent span to which I
attach this event, instead of to all of them.

on the other hand, if I run a loop on all the spans together and
attach the events within that loop, then they all work. But only want
to attach an observer once, at the moment the span is created.

The difference in the loop is that one is cycling through dom element,
such as :
<code>
X = $$('span.xspan'); // gets a collection of span elements I'm
interested in
X.each(function(item) {
// Event.observe(item, "click",
this.deleteitem.bindAsEventListener(item, item.id));
}.bind(this));\
</code>

so "item" is not the same sort of thing as "xspanid" above. Thus, I
tried it like this as well:

<code>
Event.observe($(xspanid), "click",
this.deleteitem.bindAsEventListener(this, xspanid));
</code>

with exactly the same results. Only that last span that gets passed
through here gets an observer attached to it.

I really don't understand why it works just as well, to the extent
that it does, with either an element id or the whole element as the
first argument. But that's another question.

Thanks in advance for any help.

Best

ecb

T.J. Crowder

unread,
Jul 23, 2008, 12:17:24 AM7/23/08
to Ruby on Rails: Spinoffs
Hi,

This group is essentially closed to new posts. Use the new, better-
named, hopefully-spam-free group for Prototype and script.aculo.us:

http://groups.google.com/group/prototype-scriptaculous/

prototype-s...@googlegroups.com

Hope this helps.
--
T.J. Crowder
tj / crowder software / com

ecb

unread,
Jul 23, 2008, 1:19:22 AM7/23/08
to Ruby on Rails: Spinoffs
ok. thanks.
Reply all
Reply to author
Forward
0 new messages