[Proto-Scripty] Binding functions to $$ directly
How come I got to this $$('#div1 p span.someclassName').each(function(el) { Event.observe(el, 'click', function(event) { alert('a'); }); }); instead of something like this ? $$('#div1 p span.someclassName').observe('click', function(el) { alert('b'); }); Any way to get the latter to work like in jQuery ? -- 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. 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.
RE: [Proto-Scripty] Binding functions to $$ directly
How 'bout $$('#div1 p span.someclassName').invoke('observe', 'click', function(el) Close enough? -- Jonathan Rosenberg Founder Executive Director, Tabby's Place http://www.tabbysplace.org/ -Original Message- From: prototype-scriptaculous@googlegroups.com [mailto:prototype-scriptacul...@googlegroups.com] On Behalf Of Phonethics Sent: Monday, May 10, 2010 10:43 AM To: Prototype script.aculo.us Subject: [Proto-Scripty] Binding functions to $$ directly How come I got to this $$('#div1 p span.someclassName').each(function(el) { Event.observe(el, 'click', function(event) { alert('a'); }); }); instead of something like this ? $$('#div1 p span.someclassName').observe('click', function(el) { alert('b'); }); Any way to get the latter to work like in jQuery ? -- 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. 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. -- 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. 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.
Re: [Proto-Scripty] Binding functions to $$ directly
jQuery conflates the meaning of $ and $$ in a useful manner, but Prototype provides the invoke function to shortcut what you are doing here. $$('#div1 p span.someclassName').invoke('observe','click', function(el) { alert('b'); }); To my mind, it's a little less magic and a lot more intentional. Note also in this case that where you have el, the reference is really to the click event, so I would write this as function(evt) just to note that. Prototype also scopes 'this' inside of your looped function, so if you wanted to alert(this), you would get the individual span element as your value. Walter On May 10, 2010, at 10:43 AM, Phonethics wrote: How come I got to this $$('#div1 p span.someclassName').each(function(el) { Event.observe(el, 'click', function(event) { alert('a'); }); }); instead of something like this ? $$('#div1 p span.someclassName').observe('click', function(el) { alert('b'); }); Any way to get the latter to work like in jQuery ? -- 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 . -- 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. 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.
Re: [Proto-Scripty] Binding functions to $$ directly
Jquery also references this inside the function as the object / element clicked.. Alex Mcauley http://www.thevacancymarket.com - Original Message - From: Walter Lee Davis wa...@wdstudio.com To: prototype-scriptaculous@googlegroups.com Sent: Monday, May 10, 2010 3:55 PM Subject: Re: [Proto-Scripty] Binding functions to $$ directly jQuery conflates the meaning of $ and $$ in a useful manner, but Prototype provides the invoke function to shortcut what you are doing here. $$('#div1 p span.someclassName').invoke('observe','click', function(el) { alert('b'); }); To my mind, it's a little less magic and a lot more intentional. Note also in this case that where you have el, the reference is really to the click event, so I would write this as function(evt) just to note that. Prototype also scopes 'this' inside of your looped function, so if you wanted to alert(this), you would get the individual span element as your value. Walter On May 10, 2010, at 10:43 AM, Phonethics wrote: How come I got to this $$('#div1 p span.someclassName').each(function(el) { Event.observe(el, 'click', function(event) { alert('a'); }); }); instead of something like this ? $$('#div1 p span.someclassName').observe('click', function(el) { alert('b'); }); Any way to get the latter to work like in jQuery ? -- 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 . -- 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. 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. -- 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. 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.