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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:05:29+00:00 2026-06-01T02:05:29+00:00

I know there is a simple way to do this but I can’t seem

  • 0

I know there is a simple way to do this but I can’t seem to find it. I have a drop down box, which has a list. Once you hover your mouse over any one of the items on the list, it’s encircled by a border. This is great.

What I want is for when a user selects an item from this list. It will automatically change the background colour to #ddd.

If the user selects another item from the list, it will deselect the other item items background.

So, I have a class called ‘hi’.

My CSS is like so:

#changer a{
    padding:3px;
    border: solid 1px #fff;    
}
#changer a.hi{
    background:#ddd;
}
#changer a:hover{
    border: solid 1px #ddd;
    text-decoration:none;
}

I’ve added this script but it just selects the item from the list but it doesn’t deselect the other one. It just toggles the background colours.

<script type="text/javascript">
$(function() {
  $("a").click(function() {
    $(this).toggleClass("hi");
  });
});
</script> 

Any help would be mostly appreciated.

Cheers,

Jonny

  • 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-01T02:05:30+00:00Added an answer on June 1, 2026 at 2:05 am

    Try this:

    $("a").click(function() {
    
        // remove existing "hi"s on other links
        $("a.hi").not(this).removeClass("hi");
    
        // toggle "hi" on this
        $(this).toggleClass("hi");
    });
    

    If you want the links to behave like mutually-exclusive checkboxes (can only select one, but can also deselect current) then use the above code, but if you want them to behave like a set of radio buttons (can only select one, but can’t deselect current), use the following instead.

    $("a").click(function() {
    
        // remove existing "hi"s on other links
        $("a.hi").not(this).removeClass("hi");
    
        // add "hi" to this
        if (!$(this).hasClass('hi'))
            $(this).addClass("hi");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know there's probably a simple way to do this, but I can't seem
I know this is a simple question for someone out there, but I have
I know there must be a simple way to do this but for the
I know there should be a simple fix for this, but im braindead at
I know there must be a really simple answer to this question, but I
I know that I can do this via profiles in Firefox, but is there
There is probably a very simple way of doing this, but this is a
I just wish to know if there is a simple way to call a
Is there a simple way of rendering to a BufferedImage in Java3D? I know
I'd like to know if there is a simple (or already created) way of

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.