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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:32:17+00:00 2026-05-18T21:32:17+00:00

I have a color palette: css .colors {width:75px;height:75px;background-color:red;border:1px solid #000;} .highlight {width:75px;height:75px;background-color:red;border:2px solid #000;}

  • 0

I have a color palette:

css

.colors {width:75px;height:75px;background-color:red;border:1px solid #000;}
.highlight {width:75px;height:75px;background-color:red;border:2px solid #000;}

html

<div class="colors">Red</div>
<div class="colors">blue</div>
<div class="colors">green</div>

the user supposed to choose what color he want,
so I want the border of the the color chosen by the user to be 2px;

$("div").click(function () {
  $(this).toggleClass("highlight");
});

this is work fine, but when i click on anothe color the old color still actived and when i click on the same color becomes inactive and i don’t want that.

what i want is:

  1. border change when active.
  2. if i click on another one the old one becomes inactive.
  3. when i click on the active one again I dono’t want something to happen i want it as it was actived.

Thank you.

  • 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-18T21:32:18+00:00Added an answer on May 18, 2026 at 9:32 pm

    What you want would look like this:

    $("div").click(function () {
      $(this).addClass("highlight").siblings().removeClass("highlight");
    });
    

    You can test it out here. What this does is just add the class on click (not toggle it so it can come off) via .addClass() then those .siblings()get the class removed via .removeClass().


    If your example is off and they’re not siblings, just use .removeClass() on the same selector as your .click() handler before adding it to the clicked element, like this:

    $("div").click(function () {
      $("div").removeClass("highlight");
      $(this).addClass("highlight");
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my CSS I have .footer a {color :red} .footer b {color :green} in
I have a 8-bit color palette, therefore I am having 256 colors. The palette
Starting a new rails project and we have a well-thought-out color palette, and want
My scenario: I have one color background image JPG. I have one black text
Anyone know why CSS provides color for text, but does not have font-color or
I have a background color applied to a ListView <style name=CKButtons> <item name=android:windowBackground>@color/window_background</item> </style>
I have an array apple color: red price: 2 orange color: orange price: 3
I have two objects: Color and Palette. Each palette can get a range of
What would be the easiest way to have the color of a text field
Can we have alternate Row color to GtkMenu items? and how to increase menu

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.