Gregory Hill
2006-Mar-01 19:46 UTC
RE: manipulate <td>''s and their content bygrabbingtheir classNames
> Or... > > var myTDs = new Array(); > $A($("main").childNodes).each(function(tr) > { > $A(tr.childNodes).each(function(td) > { > myTDs.push(td); > }); > });You''ll probably want to make sure the tr elements are TR tags and the same for the td''s, as empty text nodes are inserted randomly by the gecko engine (and maybe others). Greg
Ryan Gahl
2006-Mar-01 19:48 UTC
RE: manipulate <td>''s and their content bygrabbingtheir classNames
I apologize... Didn''t answer the whole question... Yes, for this type of thing I use a separate behavior class (similar to troels'') controller. You can make the td''s extend this controller class, and one difference I make is that I never put javascript handlers in the markup... But as far as grabbing the references to all the td''s, my method below works. -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of Ryan Gahl Sent: Wednesday, March 01, 2006 1:43 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: RE: [Rails-spinoffs] manipulate <td>''s and their content bygrabbingtheir classNames Or... var myTDs = new Array(); $A($("main").childNodes).each(function(tr) { $A(tr.childNodes).each(function(td) { myTDs.push(td); }); }); -----Original Message----- From: rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org [mailto:rails-spinoffs-bounces-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org] On Behalf Of troels knak-nielsen Sent: Wednesday, March 01, 2006 12:28 PM To: rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org Subject: Re: [Rails-spinoffs] manipulate <td>''s and their content by grabbingtheir classNames <p align=\"left\"><b><font face=\"Arial\" size=\"2\">GFI MailSecurity''s HTML threat engine found HTML scripts in this email and has disabled them.</font></b></p>You could make a controller-object, which keeps a pointer to the selected index, rather than traversing through the dom each time you change the active cell. Something along : <Xcript type="text/javascript"><!-- MyController = { selected : null, select : function(elm) { if (this.selected) { this.selected.className = ""; } this.selected = elm; elm.className = "selected"; } } --></Xcript> <table> <tr> <td onclick="MyController.select(this)">foo</td> <tr> <tr> <td onclick="MyController.select(this)">bar</td> <tr> </table> On 3/1/06, Maninder, Singh <mandiv-W2hqgAdRMsX2eFz/2MeuCQ@public.gmane.org> wrote:> > Hi Guys, > > What''s the best way to grab all <td>''s in a particular table and > manipulate them? > > Here''s the problem definition - > > I have a table that has ''n'' <tr>''s. > Each <tr> has couple of <td>''s and the first <td> has an image. > > By default, each <td> has a ''x'' class and image src is ''x.gif''. > But, when one is clicked, that one needs to be modified - the <td> > class should change to ''y'' and image src to ''y.gif''. > Simultaneously need to traverse through other <tr>''s and change the > classes of the <td>''s to ''x'' and their graphics to ''x.gif'' so that I > don''t need to remember which one was highlighted earlier and which oneis highlighted now.> > Eg: > > <table> > <tbody id=main> > <tr> > <td class=x><a href=#><img src=x.gif></a></td> > <td class=x>foo</td> > </tr> > > <!-- ACTIVE --> > <tr> > <td class=y><a href=#><img src=y.gif></a></td> > <td class=y>foo</td> > </tr> > <!-- ACTIVE --> > > <tr> > <td class=x><a href=#><img src=x.gif></a></td> > <td class=x>foo</td> > </tr> > </tbody> > </table> > > Would the $$ function be the best bet? > > Thoughts would be appreciated. > > Thank you, > Mandy. > _______________________________________________ > Rails-spinoffs mailing list > Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs > > >-- mvh troels www.kyberfabrikken.dk _______________________________________________ Rails-spinoffs mailing list Rails-spinoffs-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs 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
Ryan Gahl
2006-Mar-01 19:54 UTC
RE: manipulate <td>''s and their content bygrabbingtheir classNames
Or... var myTDs = new Array(); $A($("main").getElementsByTagName("tr")).each(function(tr) { $A(tr.getElementsByTagName("td").each(function(td) { Object.extend(td, TDControllerClass); // added this just to show how to attach behaviors like this myTDs.push(td); }); }); 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.
Reasonably Related Threads
- RE: manipulate <td>''s and their contentbygrabbingtheir classNames
- RE: manipulate <td>''s and their content by grabbingtheir classNames
- manipulate <td>''s and their content by grabbing their classNames
- RE: manipulate <td>''s andtheircontentbygrabbingtheir classNames
- RE: manipulate <td>''s and theircontentbygrabbingtheir classNames