can you please tell me why this is not working? i got the example for how to use each online and copied it to a t (except i added the if). its telling me items.each does not exist. var items = document.getElementsByClassName(''editView''); if (items.length > 0){ items.each(function (result){ thisid = result.id; thiskey = thisid.replace(/se_item_/gi, ''''); selist_toggleEdit(thiskey,''display''); }); }
You first have to convert it to an enumerable array (use the $A() helper method for that)... $A(items).each(etc.. etc..); The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
Louis, document.getElementsByClassName returns a node list. You need to turn it into an array: var nodeList = document.getElementsByClassName(''editView''); var items = $A(nodeList); -Matt On Mar 16, 2006, at 1:04 PM, Louis Walch wrote:> can you please tell me why this is not working? i got the example > for how > to use each online and copied it to a t (except i added the if). its > telling me items.each does not exist. > > var items = document.getElementsByClassName(''editView''); > > if (items.length > 0){ > items.each(function (result){ > thisid = result.id; > thiskey = thisid.replace(/se_item_/gi, ''''); > selist_toggleEdit(thiskey,''display''); > }); > } > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
oh, i thought it returned an array.... i guess because it worked with a for loop, and i figured that required an array.> Louis, > > document.getElementsByClassName returns a node list. You need to turn > it into an array: > > var nodeList = document.getElementsByClassName(''editView''); > var items = $A(nodeList); > > -Matt > > > On Mar 16, 2006, at 1:04 PM, Louis Walch wrote: > >> can you please tell me why this is not working? i got the example >> for how >> to use each online and copied it to a t (except i added the if). its >> telling me items.each does not exist. >> >> var items = document.getElementsByClassName(''editView''); >> >> if (items.length > 0){ >> items.each(function (result){ >> thisid = result.id; >> thiskey = thisid.replace(/se_item_/gi, ''''); >> selist_toggleEdit(thiskey,''display''); >> }); >> } >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
i tried both solutions and both did not work.... var items = document.getElementsByClassName(''editView''); if (items.length > 0){ $A(items).each(function (result){ //blah blah }); } ERROR: (items).each is not a function var items = $A(document.getElementsByClassName(''editView'')); if (items.length > 0){ items.each(function (result){ //blah blah }); } ERROR: items.each is not a function> Louis, > > document.getElementsByClassName returns a node list. You need to turn > it into an array: > > var nodeList = document.getElementsByClassName(''editView''); > var items = $A(nodeList); > > -Matt > > > On Mar 16, 2006, at 1:04 PM, Louis Walch wrote: > >> can you please tell me why this is not working? i got the example >> for how >> to use each online and copied it to a t (except i added the if). its >> telling me items.each does not exist. >> >> var items = document.getElementsByClassName(''editView''); >> >> if (items.length > 0){ >> items.each(function (result){ >> thisid = result.id; >> thiskey = thisid.replace(/se_item_/gi, ''''); >> selist_toggleEdit(thiskey,''display''); >> }); >> } >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
...and you''re sure that prototype is loaded? Otherwise, I guess just do a for loop. The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
yea its loaded... i will just put it back into the for loop, i was just currious to start using each.> ...and you''re sure that prototype is loaded? > > Otherwise, I guess just do a for loop. > > The information transmitted in this electronic mail is intended only for > the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender > and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Yea, each is awesome... are you able to use it with a regular array (not a nodeList). Might be worth just testing that to make sure something''s not wrong with your prototype lib... (I''m not sure if I''ve ever tried it with a nodeList or not, but am surprised if it really just won''t work...) The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
For what it''s worth, I may have been wrong when I said it returns a node list. I was thinking of getElementsByTagName getElementsByClassName comes with prototype (and other libs) and would probably return an Array. Louis, what version of prototype are you running? Any other JS libs that may be conflicting in some way? -Matt On Mar 16, 2006, at 1:41 PM, Ryan Gahl wrote:> Yea, each is awesome... are you able to use it with a regular array > (not > a nodeList). Might be worth just testing that to make sure something''s > not wrong with your prototype lib... (I''m not sure if I''ve ever > tried it > with a nodeList or not, but am surprised if it really just won''t > work...) > > The information transmitted in this electronic mail is intended > only for the > person or entity to which it is addressed and may contain > confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance > upon, > this information by persons or entities other than the intended > recipient > is prohibited. If you received this in error, please contact the > sender and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
i have prototype 1.4.0 pre_2 and the only other lib i have is scriptaculous> For what it''s worth, I may have been wrong when I said it returns a > node list. I was thinking of getElementsByTagName > > getElementsByClassName comes with prototype (and other libs) and > would probably return an Array. > > Louis, what version of prototype are you running? Any other JS libs > that may be conflicting in some way? > > -Matt > > On Mar 16, 2006, at 1:41 PM, Ryan Gahl wrote: > >> Yea, each is awesome... are you able to use it with a regular array >> (not >> a nodeList). Might be worth just testing that to make sure something''s >> not wrong with your prototype lib... (I''m not sure if I''ve ever >> tried it >> with a nodeList or not, but am surprised if it really just won''t >> work...) >> >> The information transmitted in this electronic mail is intended >> only for the >> person or entity to which it is addressed and may contain >> confidential, >> proprietary, and/or privileged material. Any review, retransmission, >> dissemination or other use of, or taking of any action in reliance >> upon, >> this information by persons or entities other than the intended >> recipient >> is prohibited. If you received this in error, please contact the >> sender and >> delete the material from all computers. >> >> _______________________________________________ >> Rails-spinoffs mailing list >> Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org >> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Oh yea I didn''t catch that either... so that would make my question about whether or no prototype was running seem dumb... When I see "getElementsByClassName" my mind always thinks "getElementsByTagName" too.. The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
Try: var editViewItems = ... instead of var items = ... Just to make sure there''s no variable conflict. -Matt On Mar 16, 2006, at 2:08 PM, Louis Walch wrote:> i have prototype 1.4.0 pre_2 > and the only other lib i have is scriptaculous > > >
But he already tried straight $A(document.getElementsByClassName("blah")).each(blah..); I don''t use the pre_2 (or whatever) version (only the str8 1.4 release), otherwise I would check what getElementsByClassName is actually returning to help more... perhaps you should do the same? The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
no dice dude editViewItems.each is not a function> Try: > var editViewItems = ... > instead of > var items = ... > > Just to make sure there''s no variable conflict. > > -Matt > > On Mar 16, 2006, at 2:08 PM, Louis Walch wrote: > >> i have prototype 1.4.0 pre_2 >> and the only other lib i have is scriptaculous >> >> >> > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
is there an easy way to echo whats inside it without looping content?> But he already tried straight > > $A(document.getElementsByClassName("blah")).each(blah..); > > I don''t use the pre_2 (or whatever) version (only the str8 1.4 release), > otherwise I would check what getElementsByClassName is actually > returning to help more... perhaps you should do the same? > > The information transmitted in this electronic mail is intended only for > the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender > and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
Don''t know... try digging into the code to see what that method is returning though. I would if I had that version of proto. The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers.
This works perfectly with me (scriptaculous 1.5.3, prototype 1.4.0): <html> <head> <script src="/js/prototype.js" type="text/javascript"></script> <script src="/js/scriptaculous.js" type="text/javascript"></script> </head> <body> <div id="editView1" class="editView">test1</div> <div id="editView2" class="editView">test2</div> <div id="editView3" class="editView">test3</div> <div id="editView4" class="editView">test4</div> <script> var items = document.getElementsByClassName(''editView''); if (items.length > 0){ items.each(function (result){ alert( result.id); }); } </script> </body> </html> On 3/16/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote:> > Don''t know... try digging into the code to see what that method is > returning though. I would if I had that version of proto. > > The information transmitted in this electronic mail is intended only for > the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender > and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >-- ===========================Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org =========================== _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
oh dude. must have been a bug in the old version. i upgraded to the latest version and it works fine :) thanks for all the help!> Don''t know... try digging into the code to see what that method is > returning though. I would if I had that version of proto. > > The information transmitted in this electronic mail is intended only for > the > person or entity to which it is addressed and may contain confidential, > proprietary, and/or privileged material. Any review, retransmission, > dissemination or other use of, or taking of any action in reliance upon, > this information by persons or entities other than the intended recipient > is prohibited. If you received this in error, please contact the sender > and > delete the material from all computers. > > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs >
That''s what my guess was, seems, OP dude, that something is messdeded up which yo proto lib. :-) _____ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Brian Peiris Sent: Thursday, March 16, 2006 4:29 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] help with each This works perfectly with me (scriptaculous 1.5.3, prototype 1.4.0): <html> <head> <script src="/js/prototype.js" type="text/javascript"></script> <script src="/js/scriptaculous.js" type="text/javascript"></script> </head> <body> <div id="editView1" class="editView">test1</div> <div id="editView2" class="editView">test2</div> <div id="editView3" class="editView">test3</div> <div id="editView4" class="editView">test4</div> <script> var items = document.getElementsByClassName(''editView''); if (items.length > 0){ items.each(function (result){ alert( result.id); }); } </script> </body> </html> On 3/16/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org > wrote: Don''t know... try digging into the code to see what that method is returning though. I would if I had that version of proto. The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs -- ============================ Brian Peiris Brampton, Ontario, Canada brianpeiris-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org or brianpeiris-PkbjNfxxIARBDgjK7y7TUQ@public.gmane.org ============================ The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
hello there, what is the diference exactly between the two arrays? On 3/16/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org> wrote:> > You first have to convert it to an enumerable array (use the $A() helper > method for that)... >-- // // Ing. Francisco J. Calderón S. // fjcalderon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org // Usuario de GNU/Linux nº 349529 // Maracay, Venezuela // _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
If you go back through that thread from yesterday, you''ll see that I (and the other responder) made the mistake of seeing "getElementsByClassName" and thinking he was talking about "getElementsByTagName". So we were both barking down the wrong tree, saying you had convert the nodeList into a prototype friendly enumerable array. The OP''s problem turned out to be a corrupted version of the prototype.js file. Not sure how his got messed up, but he re-downloaded it and said it works fine now. ________________________________ From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Francisco Calderon Sent: Friday, March 17, 2006 6:11 AM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] help with each hello there, what is the diference exactly between the two arrays? On 3/16/06, Ryan Gahl <Ryan.Gahl-nlycWCgr5/vuufBYgWm87A@public.gmane.org > wrote: You first have to convert it to an enumerable array (use the $A() helper method for that)... -- // // Ing. Francisco J. Calderón S. // fjcalderon-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org // Usuario de GNU/Linux nº 349529 // Maracay, Venezuela // The information transmitted in this electronic mail is intended only for the person or entity to which it is addressed and may contain confidential, proprietary, and/or privileged material. Any review, retransmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from all computers. _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs