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 <[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

Reply via email to