title: Add/Remove class onclick with JavaScript no librarys
body: <p>I am developing a mobile site and want to use JS for nothing more than adding and removing classes. So, in the interest of keeping things nice and light I don't want to use jQuery.</p>
  
  <p>I have the following HTML:</p>
  
  <pre><code>&lt;div id="masthead"&gt;
      &lt;a href="index.html" title="Home" id="brand"&gt;Brand&lt;/a&gt;
  
      &lt;a href="#" id="openPrimaryNav"&gt;Menu&lt;/a&gt;
  
      &lt;ul id="primaryNav" class=""&gt;
          &lt;li&gt;&lt;a href="index.html" title="Home"&gt;Home&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="benefits.html" title="Benefits"&gt;Benefits&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="features.html" title="Features"&gt;Features&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="casestudies.html" title="Case Studies"&gt;Case Studies&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="instore.html" title="In Store"&gt;In-Store&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="contact.html" title="Contact"&gt;Contact Us&lt;/a&gt;&lt;/li&gt;
          &lt;li id="closePrimaryNav"&gt;&lt;a href="#" title="Contact"&gt;Close Menu&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>and the following JS so far:</p>
  
  <pre><code>window.onLoad = init;
  
  function init()
  {
      document.getElementById('openPrimaryNav').onClick   = openPrimaryNav();
      document.getElementById('closePrimaryNav').onClick  = closePrimaryNav();
  }
  
  function openPrimaryNav()
  {
      document.getElementById('primaryNav').className = 'open';
  }
  
  function closePrimaryNav()
  {
      document.getElementById('primaryNav').className = '';
  }
  </code></pre>
  
  <p>I cannot get this working can anyone tell me what I am doing wrong? Many thanks in advance.</p>
  
  <p>CORRECT JS BASED ON ANSWER PROVIDED BELOW:</p>
  
  <pre><code>window.onload = init;
  
  function init()
  {
      document.getElementById('openPrimaryNav').onclick   = openPrimaryNav;
      document.getElementById('closePrimaryNav').onclick  = closePrimaryNav;
  }
  
  function openPrimaryNav()
  {
      document.getElementById('primaryNav').setAttribute('class','open');
  }
  
  function closePrimaryNav()
  {
      document.getElementById('primaryNav').setAttribute('class','');
  }
  </code></pre>