Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7620267
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:53:53+00:00 2026-05-31T03:53:53+00:00

I have a menu with links. The links are placed inside a table. Each

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T03:53:54+00:00Added an answer on May 31, 2026 at 3:53 am

    You should refer to the current element and not all elements matching your selector.

    $("#mainMenu td").click(function() {
        $(this).css('background-color', '#EDEDED');
    });
    

    I´d also recommend you to use CSS classes instead of setting the CSS properties this way.

    That would be something like;

    $("#mainMenu td").click(function() {
        $(this).addClass('selected');
    });
    

    together with;

    #mainMenu td.selected {
      background-color: #EDEDED;
    }
    

    EDIT

    The psuedo selector :visited should only be used on links (a) and you should not use tables more than you really need to.

    Created a jsFiddle that uses an ul list instead of the table and display: block on links to fill the entire parent li element.

    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.

    $("#mainMenu a").click(function(e) {
        e.preventDefault(); // Don´t follow the link
        $("#mainMenu a").removeClass('selected'); // Remove class on all menu items
        $(this).addClass('selected'); // Add class to current menu item
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have an outline where I have links for my menu. Each link
I want to have the context menu of links provide me an option to
I have a menu of report links in my master page. I need to
In menu.html, I have my menu items(a href links), let's call them, menu_1, menu_2,
I have the following two links in my main menu, and I have some
I have a sliding JS menu that opens when you click the noty_menu link,
I have a menu system where when you click on a link, sub-headings will
I am building a website www.etutornetwork.com, in top menu I have included a link
I have a simple link in a menu <a id=Home href=Amico-Bio-Home-Page></a> to which i
I have a flash file menu i am having problem while link it to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.