Hi,

I also think delegation is the better approach.
However, I did notice that none of the examples was dealing with the
case where the user click on something that is not a '.item'.

You may want to do something like this:

function doIt(e) {
  var element = e.findElement('.item');
  if(element != document)
  {
    var id = element.id;
    // Do your stuffs here
  }
}

Eric

On Nov 18, 1:47 pm, ColinFine <colin.f...@pace.com> wrote:
> On Nov 17, 10:17 pm, phegaro <pheg...@gmail.com> wrote:
>
>
>
> > Delegation sounds like a good model for doing this although if i want
> > to pass parameters that are custom to each node like which id did it
> > click on then i assume i have store it as a property on the node and
> > pass arguments to the delgated function?
>
> > In the above example if doIt took a paramter of the id to work on,
>
> > doIt(id)  {
> > // do something to the object with id X
> > ...
>
> > }
>
> > Then with the delegation model i would have to retreive the node using
> > findelement and then have an attribute on the node that held the id?
> > Is that right?
>
> Yes, clearly; if the processing is different for different element
> then a delegation model requires you to determine which element you
> are processing and choose your processing accordingly.
>
> If each item is distinct, give them all an HTML 'id', and just use
> that:
>
> function doIt(e) {
> var element = e.findElement('.item');
>  var id = element.id;
>
> If there are classes of them, it's easiest to use CSS classes:
>
> <span class='item click_class_1'> ...
>
> function doIt(e) {
>  var element = e.findElement('.item');
>  var class_1 = element.hasClassName('click_class_1');
>
> or more generally
>
> function doIt(e) {
>   var element = e.findElement('.item');
>   if (var matches = element.className.match(/click_class_(\n+)/) {
>     var clickclass = matches[1]);

--

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-scriptacul...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=.


Reply via email to