Your code works correctly, even though this is a bad style. I do understand your ugly colors are just for example. You should not ever change background color for such cases.
The reason you may not see the difference is your visited links: which links are visited are defined by what's in the cash of your Browser. I try to test your code and did not see the difference between visited and not-visited links because it so happened that both ones from my test were actually visited.
As soon as I've chosen the link which I never visited (alternatively, you could wipe your browser's cash), you code started to work correctly.
[EDIT]
In response to discussion of the style: look at my two Answers to this Question:
GUI Apperance - C#.Net[
^].
Sorry this is not even about Web development, but it may give you some idea on how I approach it.
What do you think? I would be glad to here your opinion.
—SA