title: How to make a div flip on button press?
body: <p>I'm trying to make a div flip once a button has been clicked, but it doesn't seem to be working correctly and I can't figure out why. I was wondering if anybody would be able to point me in the right direction and correct my errors.</p>
  
  <p><strong>My code:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var init = function() {
    var card = document.getElementById('card');
  
    document.getElementById('flip').addEventListener('click', function() {
      card.toggleClassName('flipped');
    }, false);
  };
  
  window.addEventListener('DOMContentLoaded', init, false);</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.container {
    width: 200px;
    height: 260px;
    position: relative;
    perspective: 800px;
  }
  #card {
    width: 100%;
    height: 100%;
    position: absolute;
    transform-style: preserve-3d;
    transition: transform 1s;
  }
  #card figure {
    margin: 0;
    display: block;
    position: absolute;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
  }
  #card .front {
    background: red;
  }
  #card .back {
    background: blue;
    transform: rotateY(180deg);
  }
  #card.flipped {
    transform: rotateY(180deg);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;section class="container"&gt;
    &lt;div id="card"&gt;
      &lt;figure class="front"&gt;1&lt;/figure&gt;
      &lt;figure class="back"&gt;2&lt;/figure&gt;
    &lt;/div&gt;
  &lt;/section&gt;
  
  &lt;section id="options"&gt;
    &lt;p&gt;
      &lt;button id="flip"&gt;Flip Card&lt;/button&gt;
    &lt;/p&gt;
  &lt;/section&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>You can find a JSFiddle <a href="https://jsfiddle.net/scf0ma4c/3/" rel="nofollow">here</a>.</p>
  
  <p>Thank you.</p>