You've got the right idea; just two problems:
the first problem isn't really a *huge* deal, but if you want to do things right, use
document.getElementById('myImage')
instead of
document.myImage
the second problem is that "class" is a reserved keyword in JavaScript, so to get to the class of an element, you use "className" instead.
The final statement is:
document.getElementById('myImage').className = 'class2';
Note that it is possible to assign an element to multiple classes by using a space-separated list (class="class1 class2 class3"). Because of this, simply assigning a new value to className can be a bad idea since it will overwrite all of the classes assigned to an element with the single class that you're assigning. But if you're only using this on specific pieces of code where you know that's not a problem, then you don't really have to worry about it.