title: JS Change class of element
body: <p>All I'm trying to do is toggle the class of an elements by ID when they are clicked on.</p>
  
  <pre><code>&lt;script&gt;
  
  function selectLoad(id)
  {
      if(document.getElementById(id).className == "load") {
          document.getElementById(id).className = "loadSelected";
      } else {
          document.getElementById(id).className = "load";
      }
  }
  
  &lt;/script&gt;
  
  &lt;div class="load" id=" ... set by PHP per element ... " onclick="selectLoad(this)"&gt;
  </code></pre>
  
  <p>This returns an error...</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'className' of null</p>
  </blockquote>
  
  <p>So I guess it doesn't like the conditional.</p>
  
  <p>I'm new to JS and need help, thanks in advance.</p>