I have a menu with links. The links are placed inside a table. Each link is placed in a <td>. I want to change the background color of the <td> when its active. How am I gonna do it in jquery?
Here is the link to my code: http://jsfiddle.net/DdG8m/.
My problem is that if one the links is clicked the background color of the whole table changes. Please help. Thanks in advance.
You should refer to the current element and not all elements matching your selector.
I´d also recommend you to use CSS classes instead of setting the CSS properties this way.
That would be something like;
together with;
EDIT
The psuedo selector
:visitedshould only be used on links (a) and you should not usetables more than you really need to.Created a jsFiddle that uses an
ullist instead of the table anddisplay: blockon links to fill the entire parentlielement.I´m also using event.preventDefault() to not follow the link as this probably would reload the page and not include the class for the selected/active link. If you want to follow the link and have the page reload you should use server side code to render that HTML.