You could write the page thus:
<div id="mainContent"> ... </div>
this.className = ( this.className == "example") ? "" : "example";
} /* end of anonymous master function */
)( ); /* self-invoke master function */
Notice that I also rewrote the onclick to be much simpler/more efficient. It could have been written that way in tho original.