View Single Post
Old 11-15-2012, 05:16 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,573
Thanks: 62
Thanked 4,061 Times in 4,030 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
And *IF* you followed Felgall's suggestion for writing modern JavaScript, it is all a non-issue.

You could write the page thus:
Code:
<html>
<body>
   <div id="mainContent"> ... </div>

<script type="text/javascript">
(
    function( )
    {
         
	document.getElementById("mainContent").onclick = 
            function() 
            {
                this.className = ( this.className == "example") ? "" : "example";
            }
    } /* end of anonymous master function */

)( ); /* self-invoke master function */
</script>
</body>
</html>
Notice that I also rewrote the onclick to be much simpler/more efficient. It could have been written that way in tho original.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is online now   Reply With Quote