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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Ryan
Gahl
Sent: Wednesday, March 01, 2006 1:43 PM
To: rails-spinoffs@lists.rubyonrails.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: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of
troels knak-nielsen
Sent: Wednesday, March 01, 2006 12:28 PM
To: rails-spinoffs@lists.rubyonrails.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 <[EMAIL PROTECTED]> 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@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
>
>
>


--
mvh troels
www.kyberfabrikken.dk
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.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@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs
_______________________________________________
Rails-spinoffs mailing list
Rails-spinoffs@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs

Reply via email to