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 8251745
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:20:15+00:00 2026-06-08T00:20:15+00:00

I am having problems applying CSS using jQuery on navigation panel. When user clicks

  • 0

I am having problems applying CSS using jQuery on navigation panel. When user clicks a link, the class .selected should get applied.

My html code is

 <ul id="example-two">
        <li><a href="#">About Us</a></li>
        <li><a href="#">Services</a></li>
        <li><a href="#">People</a></li>
        <li><a href="#">Career</a></li>
        <li><a href="#">Contact Us</a></li>
        <li><a href="#">Videos</a></li>
    </ul>    

My CSS code is

#example-two li a { 
  position: relative; 
  z-index: 200;
  background-image: -moz-linear-gradient(#6C6C6C, #4A4A4A);
  border-radius:10px; 
  color: #FFF; 
  font-size: 14px; 
  display: block; 
  float: left; 
  padding: 6px 10px 4px 10px;
  text-decoration: none;
  text-transform: uppercase; 
}
#example-two li a:hover {
    background-image: -moz-linear-gradient(#ed2024, #c8171a);
    color: white; 
}

.selected{
    background-image: -moz-linear-gradient(#ed2024, #c8171a);
    color: white;
}

And my jQuery code is

<script>
$(document).ready(function() {
    $('ul#example-two li a').click(function() {
       $('ul#example-two li a').removeClass("selected");
       $(this).addClass("selected");
    });
})
</script>

Any idea, where am going wrong ?

  • 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-08T00:20:17+00:00Added an answer on June 8, 2026 at 12:20 am

    You are overriding the background image value in your top CSS selector. See here for more info on css precedence.

    Change .selected to #example-two li a.selected

    http://jsfiddle.net/EuuhZ/1/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some problems with my ul -list after using applying CSS-reset. When the
I've created a page using JQuery and Ajax that helps a user filter through
Having problems with assigning a specific id to a varied list of items selected
Having problems with my ASP.NET MVC2 project. I'm using Fluent NHibernate as ORM, and
I am having enormous problems applying my styles to the Breadcrumb NavXT plugin. When
It's seems very curious but I'm having problems applying styles for javascript generated elements
I am having problems with my code. It should take an object containing 4
We are having problems trying to get Polish characters to appear correctly on our
I'm using Particle Swarm Optimization(PSO) in java. I am having little knowledge about what
Having problems with IE8... I have a button that onclick fires the showImageBrowser() function.

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.