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

  • Home
  • SEARCH
  • 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 7720081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:34:28+00:00 2026-06-01T03:34:28+00:00

I am trying to write, what I thought was, a simple jQuery function to

  • 0

I am trying to write, what I thought was, a simple jQuery function to switch the look of a selected vs. not-selected tab. Here is what I have:

CSS:

ul#menu li a
{ font: normal 100% 'trebuchet ms', sans-serif;
  display: block; 
  float: left; 
  height: 20px;
  padding: 6px 28px 5px 22px;
  text-align: center;
  color: #FFF;
  text-decoration: none;
  background: #635B53 url(../images/tab.png) no-repeat 100% 0;}

ul#menu li.selected 
{ margin: 2px 2px 0 0;
  background: #635B53 url(../images/tab_selected.png) no-repeat 0 0;}

HTML:

<ul id="menu">
  <li id="menuHome"><a href="home.html">Home</a></li>
  <li id="menuNews"><a href="news.html">News</a></li>
  <li id="menuDownloads"><a href="downloads.html">Downloads</a></li>
  <li id="menuFeedback"><a href="feedback.html">Feedback</a></li>
  <li id="menuContact"><a href="contact.html">Contact Us</a></li>
</ul>

jQuery:

$('#menu li a').live ( 'click', function()
{
    $(this).parent().find('a.selected').removeClass('selected');
    $(this).parent().addClass('selected');
});

What happens is this: I click one of the tabs, the tab changes to the lighter color as it should, then it switches back to the original dark gray. I’ve run it in FireBug and it clearly shows that the jQuery function changes the tab to the light color, but when I “continue”, and the program goes back into the jQuery library, it switched it back to the original!

I have tried everything I can think of… a little help?!?

UPDATE

Even if we do not worry about removing the selected class from the wrapped set and simply concentrate on adding the class, the JQ code still performs the same. In other words, this:

$('#menu li a').live ( 'click', function()
{
    $(this).parent().addClass('selected');
});

“Flashes” the light color – it displays the lighter color then immediately returns to the darker color. Yikes! Someone is changing it back… who?

  • 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-06-01T03:34:29+00:00Added an answer on June 1, 2026 at 3:34 am

    try this:

    $('#menu li a').live ('click', function()
    {
        $("a",$(this).parents("ul")).removeClass('selected');
        $(this).addClass('selected');
    });​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to write (what I thought would be) a simple bash script that
I am trying to write a simple sieve function to calculate prime numbers in
I have a Galaxy Tab 1000. I am trying to write a code, that
I'm trying to write a simple function in C that would calculate the difference
I am trying to write a list function that takes a simple list and
I'm trying write a query to find records which don't have a matching record
Im trying to write something to get my images to show correctly. I have
Im trying to write a function for adding category: function addCategory() { $cname =
I'm trying to write a regex function that will identify and replace a single
I am trying to write a simple input field validation plugin at the moment

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.