title: Switch CSS background colour on hover and on click using Javascript
body: <p>I have been using this script to switch CSS background colour on click and I've been trying to change it so the second colour will appear on hover and the will appear on click. Can anyone help to get this to work?</p>
  
  <p>Here is my jsfiddle link:</p>
  
  <p><a href="https://jsfiddle.net/pkrWV/70/" rel="nofollow">https://jsfiddle.net/pkrWV/70/</a></p>
  
  <pre><code>var bodyObj, className, index;
  
  bodyObj = document.getElementById('body');
  index = 1;
  className = [
      'imageOne',
      'imageTwo',
       'imageThree',
  ];
  
  function updateIndex(){
      if(index === 0){
          index = 1;
      }else{
          index = 0;
      }
  }
  
  bodyObj.onclick = function(e){
      e.currentTarget.className = className[index];
      updateIndex();
  }
  </code></pre>