Re: Traversing through DOM, identifying td's and manipulating

Joris Huizer <[email protected]> Wed, 01 Mar 2006 19:58:41 +0100
Newsgroups gmane.comp.web.dom.wdf
Message-ID <[email protected]>
Maninder, Singh wrote:
> Hi Everyone,
> 
> Just want to take some expert opinion on the following problem.
> 
> I have around 5-10 rows like mentioned below.
> 
> Each of them have the same bg color except the one that would be active.
> 
> So, what I want to do is that when a particular header is clicked, I want to change the bgcolor's of the 2 td's and flip the src of the img in the first td.
> 
> What would be the best way to do this as I want to traverse through the tree, change the bgcolors and image of the one being clicked, but also change the image&bgcolors of all the rest to make sure they are not highlighted.
> 
> Help would be appreciated.
> 
> Thank you,
> Mandy.
> 
> <ACTIVE>
> 
> <tr>
>   <td bgcolor="#ffffff"><a href='#)'><img src="foo1_active.gif" border="0" height="25" width="36"></a></td>
>   <td bgcolor="#ffffff">&nbsp;<a href='#'><b>Foo1</b></a></td>
> </tr>
> 
> </ACTIVE>
> 
> <tr>
>   <td bgcolor="#305daa"><a href='#)'><img src="foo2.gif" border="0" height="25" width="36"></a></td>
>   <td bgcolor="#305daa">&nbsp;<a href='#'><b>Foo2</b></a></td>
> </tr>
> 
> 
> <tr>
>   <td bgcolor="#305daa"><a href='#)'><img src="foo3.gif" border="0" height="25" width="36"></a></td>
>   <td bgcolor="#305daa">&nbsp;<a href='#'><b>Foo3</b></a></td>
> </tr>
> 

I like to post a CSS solution:
You could have a variable indicating the previously selected td 
(initially set to some hidden cell with "display:none")
Then, when a cell is clicked, remove the class attribute of it (or set 
it to the default class) then, change the class name of the selected cell;

Although the way of setting all backgrounds will work, it's faster (and 
even less complicated / less code) when using a special class for a 
selected cell


Unsubscribe
[email protected]

List info
http://www.quirksmode.org/dom/list.html 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/wdf-dom/

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/