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:

Here is your existing code with an explanation of what it does any time any anchor tag with the class “link” is clicked:
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:
(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 settingcolor:black;in your defaulta.linkstyling:Here’s a demo: http://jsfiddle.net/nnnnnn/6qURY/