Maninder, Singh
2006-Mar-01 18:20 UTC
manipulate <td>''s and their content by grabbing their classNames
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 one is 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
troels knak-nielsen
2006-Mar-01 18:28 UTC
Re: manipulate <td>''s and their content by grabbing their classNames
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 : <script type="text/javascript"> MyController = { selected : null, select : function(elm) { if (this.selected) { this.selected.className = ""; } this.selected = elm; elm.className = "selected"; } } </script> <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 one is 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
Apparently Analagous Threads
- RE: manipulate <td>''s and their content bygrabbingtheir classNames
- RE: manipulate <td>''s and their content by grabbingtheir classNames
- RE: manipulate <td>''s and their contentbygrabbingtheir classNames
- RE: manipulate <td>''s andtheircontentbygrabbingtheir classNames
- RE: manipulate <td>''s and theircontentbygrabbingtheir classNames