I would use jQuery and write something like this:
jQuery(function($) {
$("#some-element").click(function() {
$(this).toggleClass("clicked");
});
});
This code adds a function to be called when an element of the id some-element is clicked. The function appends clicked to the element's class attribute if it's not already part of it, and removes it if it's there.
Yes you do need to add a reference to the jQuery library in your page to use this code, but at least you can feel confident the most functions in the library would work on pretty much all the modern browsers, and it will save you time implementing your own code to do the same.
Thanks