title: Only execute a function if body class exists
body: <p>I have a body class like this:</p>
  <pre><code>&lt;body class=&quot;horizontal&quot;&gt;
  </code></pre>
  <p>I try to target with the following code:</p>
  <pre><code>'use strict';
  
  // Horizontal scrolling
  // http://www.dte.web.id/2013/02/event-mouse-wheel.html
  (function() {
  if(document.body.className === 'horizontal') {
    alert('It exists');
  
    function scrollHorizontally(e) {
      e = window.event || e;
      var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail)));
      // Scroll to the left or right in `document.documentElement` and `document.body`
      document.documentElement.scrollLeft -= (delta * 75); // Multiplied by 75
      document.body.scrollLeft -= (delta * 75); // Multiplied by 75
      e.preventDefault();
    }
    if (window.addEventListener) {
      window.addEventListener('mousewheel', scrollHorizontally, false); // IE9, Chrome, Safari, Opera
      window.addEventListener('DOMMouseScroll', scrollHorizontally, false); // Firefox
    } else {
      window.attachEvent('onmousewheel', scrollHorizontally); // IE 6/7/8
    }
  };
  })();
  </code></pre>
  <p>But this is just not working. The <code>alert</code> not popping up. I would like to prefer a pure javascript solution, to not include Jquery because of this.</p>
  <p>EDIT: I uncommented the horizontal scroller function, then it's working. So the script is causing the issue.</p>
  <p>The entire script is called at the bottom of the body.</p>