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

  • Home
  • SEARCH
  • 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 7447465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:36:40+00:00 2026-05-29T12:36:40+00:00

I want the default CSS classto be black, and when using this select function

  • 0

I want the default “CSS class”to be black, and when using this select function for “selected” to have white text. I don’t know where I’m going wrong

$(function() {
   $('a.link').click(function() {
       $('a.link').removeClass('selected');
       $(this).addClass('selected');
       $(this).css('color', 'white');
       $(this).addClass('result-holder');
       $(this).css('color', 'black');


   });
});

Image demonstrating the problem:

enter image description here

http://imgur.com/AquDa

  • 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-29T12:36:41+00:00Added an answer on May 29, 2026 at 12:36 pm

    Here is your existing code with an explanation of what it does any time any anchor tag with the class “link” is clicked:

    $('a.link').removeClass('selected');   // remove 'selected' from all links
    $(this).addClass('selected');          // add 'selected' to clicked link
    $(this).css('color', 'white');         // turn clicked link 'white'
    $(this).addClass('result-holder');     // add 'result-holder' to clicked link
    $(this).css('color', 'black');         // turn clicked link 'black'
    

    You are turning the clicked link white and then turning it back to black all in the same block of code so you’ll never see it displayed as white.

    I’m pretty sure what you really want to do is as follows:

    $('a.link').removeClass('selected')    // remove 'selected' from all links
               .css('color', 'black');     // and make them black again
    
    $(this).addClass('selected')           // add 'selected' to clicked link
           .css('color', 'white').         // and turn it 'white'
    

    (Note if calling more than one function on a jQuery object you can “chain” them, like $(this).addClass('selected').css('color','white');)

    I can’t really tell what you want to do with the ‘result-holder’ class, because your current code adds it to the clicked link but doesn’t remove it from anything. If you want to add it to the clicked link say $(this).addClass('result-holder') like you already do.

    Note that you can simplify this by just adding color:white; to your ‘selected’ class definition, and setting color:black; in your default a.link styling:

    a.link {
       color : black;
    }    
    
    a.selected {
       /* your existing style settings here, then: */
       color : white;
    }
    

    Here’s a demo: http://jsfiddle.net/nnnnnn/6qURY/

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

Sidebar

Related Questions

I have a text called Default/css . I want a value Default and css
in my site i want to set default page to open, using this script
I'm using a jQuery UI Theme, which is predominantly white text on a black
how to remove CSS default class This is my div <div id=messageContainer> This is
I want to set color of some elements to default link color with CSS.
I want to write a default structure, N times, to a file, using fwrite.
I want to change the default arguments passed to a Ruby function. For example,
I want to get rid of the default css stylesheet app/assets/stylesheets/scaffold.css.scss but when I
Is there a way to point to the default CSS class of an object?
I'm currently styling form elements with a custom CSS class to style text inputs

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.