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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T10:35:29+00:00 2026-05-16T10:35:29+00:00

I have a few lists, and when a user clicks on an item I

  • 0

I have a few lists, and when a user clicks on an item I would like it to change the class to current, but if a users then clicks on another item in the same list to switch that to current and remove the current from the previous item selected.

any quick examples, i know this is probably out there already but couldn’t find a good example.

<ul id="list">
  <li>item 1</li>
  <li>item 2</li>
  <li>item 3</li>
  <li>item 4</li>
</ul>

So if you click on item 1 it will be class current, but switch off if you click on item 2.

  • 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-16T10:35:29+00:00Added an answer on May 16, 2026 at 10:35 am
    $('ul#list li').click(function(){
       $(this).addClass('current').siblings().removeClass('current');
    });
    

    references

    • addClass
    • siblings
    • removeClass

    simple demo


    It would be easy if you use the li in adding/removing current because of the siblings. But if you wan’t to use the anchors, do it this way,

    $('ul#list li a').click(function(){
       var li = $(this).parent();
       li.find('a').addClass('current');
       li.siblings().find('a').removeClass('current');
       return false;
    });
    

    or if you just want to use anchors just for the click event and still add/remove current on li, do this,

    $('ul#list li a').click(function(){
       var li = $(this).parent();
       li.addClass('current').siblings().removeClass('current');
       return false;
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few list elements, like this: <li class=item> <a class=toggle><h4>ämne<small>2010-04-17 kl 12:54
I have few different applications among which I'd like to share a C# enum.
in my app i have a button named Search, When the user clicks the
I have an iframe which contains a few select drop-down lists for data entry.
I have the following scenario - a few dropdwon lists and a textbox. I'd
I have an unordered list with a few list elements. #tags { width: 300px;
I have made a list with few elements in it. Now everything looks right,
I have a List of a complex type - an object with a few
I have a list a simple dialog box which contains a few checkboxes, I
I have a dropdown list and a select list. Both contain quite a few

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.