You're going about this in a peculiar fashion - using the class name to identify the item clicked. It's more conventional to use an id.
add an id to the image tag something like this:
<img ....="" id="space1" onclick="changeImage(id)">
</img>
and rearrange your function to something like this:
function changeImage(id) {
switch(id) {
case 'space1': do something
break;
case 'space2': do something
break;
case 'space3': do something
break;
}
}
You'll find this easier to manage - consider that a class can be used in more than one location (and ideally, your CSS will allow you to do this) - it's not the best way to test for an individual item to be identified. id's on the other hand, are
not supposed to be reused on a given page. You can also have a lot of functionality using document.getElementById()