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