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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:40:52+00:00 2026-05-27T22:40:52+00:00

I have a navigation bar: <div id=the navigation> <ul> <li><a href=#>Item 1</a></li> <li><a href=#>Item

  • 0

I have a navigation bar:

<div id="the navigation">
<ul>
    <li><a href="#">Item 1</a></li>
    <li><a href="#">Item 2</a></li>
    <li><a href="#">Item 3</a></li>
</ul>
</div>

I want it so that when the user clicks on any of the items, it becomes highlighted (for example, it should get a red background). If a different item is clicked, then the currently highlighted one should no longer be highlighted and the one that was just clicked should be. There should only be one lit at any given time.

How do I do this with jQuery?

  • 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-27T22:40:53+00:00Added an answer on May 27, 2026 at 10:40 pm

    Edit: Updated to use the actual HTML you have now posted. First, I had to remove the space your your id value as a space makes it difficult or impossible to use it in many selectors.

    <div id="thenavigation">
        <ul>
            <li><a href="#">Item 1</a></li>
            <li><a href="#">Item 2</a></li>
            <li><a href="#">Item 3</a></li>
        </ul>
    </div>
    

    I’d suggest this CSS:

    .highlight {background-color: red;}
    

    to go with this jQuery:

    $('#thenavigation li a').click(function() {
        $(this).closest("li").addClass('highlight').siblings().removeClass('highlight');
        return(false);   // no default behavior from clicking on the link
    });
    

    You can see it work here with your HTML: http://jsfiddle.net/jfriend00/r9s7w/.

    Or working here without the <a> tags: http://jsfiddle.net/jfriend00/TreKN/.

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

Sidebar

Related Questions

I have a navigation bar that tells the user which page is selected by
I want to have a navigation bar with a settings button on it that
Assuming that I have this navigation bar <div id = nav> <a class =
I have a navigation bar that I want to get the width of each
So basically I have a navigation bar on the left. When the user clicks
I have a navigation bar like this <div id=top data-role=navbar data-type=horizontal> <ul> <li><a href=#a>A</a></li>
I have a navigation bar for my website: <div id='menu'><ul> <li><a href='index.html'>Home</a></li> <li><a href='about.html'>About
I have a navigation bar that has two dropdowns (as nested ul's). I'm trying
I have a navigation bar that sticks out a little bit from the right
I have this code that is my navigation bar on my site, it is

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.