Changing css class of a link on click withing changing original code

I currently have a normal link like

<a href="http://sitepoint.com" class="link">sitepoint</a>

and when a user clicks on it I want to be able to change the “link” class to a different class. However, I don’t want to add anything to the actual link html. Is it possible to do this using javascript without modifying the original link code?

How would you like to do it without any javascript either?


a.link:active {
    background-color: silver;
}

I’m also using zeroclipboard so that won’t work. Do you have a javascript version? thanks for the help

To do it with javascript requires having some way to target the link. Do you have a sample test page from which an appropriate solution can be crafted for you?

Using jQuery:

$(‘.link’).click(function(){ $(this).addClass(‘clickedlink’).removeClass(‘link’) });

Not tested, but something like that should do what you’re after