hi there, I''m new here so hello all. Does using the $$ give extend an element like $ does? I can''t find a clear answer on this so i thought i''d post. Also can i use functions like down and each on anything or does it have to be an extended element? (obviously i know that i could only use each on an iterable object and down on an object with children) Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 23, 2008 2:27 PM, elduderino <jamesfiltness-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Does using the $$ give extend an element like $ does? I can''t find a > clear answer on this so i thought i''d post.Yes it does, but keep in mind it returns a collection of elements, not a single one. Even when your selector only matches a single element (like $$(''html body'')).> Also can i use functions like down and each on anything or does it > have to be an extended element? (obviously i know that i could only > use each on an iterable object and down on an object with children)Yes, but on individual items in the returned collection, not the entire collection itself. // hide every div with a class of "custom-class" $$(''div.custom-class'').invoke(''hide'') // iterate over the same collection, updating the *first* paragraph with new text $$(''div.custom-class'').each( function( element ){ element.down(''p'').update(''I was here''); }); -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 23, 2008 1:27 PM, elduderino <jamesfiltness-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> > Does using the $$ give extend an element like $ does?Yep! Keep in mind, though, that $$ is returns an array of elements--even if the selector you provide only matches one element, you''ll still get an array holding that single element. In that case, you''ll want to grab the element thusly: $$(selector)[0] or $$(selector).first(). That accesses the fully Prototype-extended element. The Protoype API docs have some good info, as usual: <http://www.prototypejs.org/api/utility/dollar-dollar> Hope that helps! :Dan --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Excellent answers thanks! Could i just ask one more thats just cropped up.....how do i add an id to an element i''ve just created....i''ve just done: var aTag = document.createElement(''a''); Element.extend(aTag); aTag.addClassName(''selectelement''); I want to add an id to aTag. thanks again On Jan 23, 8:47 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 23, 2008 1:27 PM, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Does using the $$ give extend an element like $ does? > > Yep! > > Keep in mind, though, that $$ is returns an array of elements--even if > the selector you provide only matches one element, you''ll still get an > array holding that single element. In that case, you''ll want to grab > the element thusly: $$(selector)[0] or $$(selector).first(). That > accesses the fully Prototype-extended element. > > The Protoype API docs have some good info, as usual: > <http://www.prototypejs.org/api/utility/dollar-dollar> > > Hope that helps! > > :Dan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 23, 2008 3:42 PM, elduderino <jamesfiltness-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> ....how do i add an id to an element i''ve just created....i''ve just > done:You''ll want to use the Element constructor for that: http://prototypejs.org/api/element new Element(''a'', { id: ''my-id'', class: ''my-class'', href: ''http://www.prototypejs.org/api/element'' }).update(''Click me to see the API for the Element object''); Much handier than the old way of doing things with document.createElement(). -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, Watch out for class... it''s a reserved keyword in JS. Prototype supports either using className (preferred imho) or ''class'': new Element(''a'', { ''class'': ''my-class'' }) new Element(''a'', { className: ''my-class'' }) Best, Tobie On Jan 23, 10:49 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 23, 2008 3:42 PM, elduderino <jamesfiltn...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > ....how do i add an id to an element i''ve just created....i''ve just > > done: > > You''ll want to use the Element constructor for that:http://prototypejs.org/api/element > > new Element(''a'', { id: ''my-id'', class: ''my-class'', href: > ''http://www.prototypejs.org/api/element''}).update(''Click me to see > the API for the Element object''); > > Much handier than the old way of doing things with document.createElement(). > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
On Jan 23, 2008 4:10 PM, Tobie Langel <tobie.langel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi, > > Watch out for class... it''s a reserved keyword in JS. Prototype > supports either using className (preferred imho) or ''class'':Oh yes, good point. Looks like somebody needs to update the Prototype API page for Element, because my code snippet is nearly identical to the one found under the section "Element as a constructor" (which mysteriously is not anchored). -justin --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Great....thanks again guys. Prototype is excellent...im working on a project to get me up to speed with it''s basic DOM stuff ( hence the innane questions) and so far ive condensed 60 lines of vanilla style javascript into just 12 in prototype javascript. Excellent stuff! On Jan 23, 10:15 pm, "Justin Perkins" <justinperk...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Jan 23, 2008 4:10 PM, Tobie Langel <tobie.lan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > Hi, > > > Watch out for class... it''s a reserved keyword in JS. Prototype > > supports either using className (preferred imho) or ''class'': > > Oh yes, good point. Looks like somebody needs to update the Prototype > API page for Element, because my code snippet is nearly identical to > the one found under the section "Element as a constructor" (which > mysteriously is not anchored). > > -justin--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---