title: How To Use An onclick Function To Check Class Name Without jQuery
body: <p>I am looking to check if a element has a class name on click. I have the click event calling the function but nothing logs to the console. Interestingly, document.write works but no matter what I click, it logs the else even if the HTML element has the class name. </p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;p&gt;What is 2+2?&lt;/p&gt;
  &lt;a href="#" class="answer wrong"&gt;5&lt;/a&gt;
  &lt;a href="#" class="answer correct"&gt;4&lt;/a&gt;
  &lt;a href="#" class="answer wrong"&gt;7&lt;/div&gt;
  &lt;a href="#" class="answer wrong"&gt;2&lt;/div&gt;
  </code></pre>
  
  <p><strong>CSS</strong></p>
  
  <pre><code>var wrongMsg = "Sorry, that's not the answer"
  var correctMsg = "Correct!"
  var answers = document.getElementsByClassName("answer");
  
  for (var i=answers.length; i--;){
      answers[i].addEventListener('click', checkMulti);
  };
  
  function checkMulti(){
      if ( this.className == "correct" ){
          console.log(correctMsg);
      }else{
          console.log(wrongMsg);
      }
  }
  </code></pre>