title: Select by .attr quiz
body: <p>I want to create a simple quiz. Any word fits into the text field, and if the word is correct, a class is set that changes color. Spent a lot of time. Please help correct the error!</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var answer = $('span').attr('data-answer');
    var submitted = $('input').val();
    $('.submit').on('click', function () {
    if (answer == submitted) {
      $('input').addClass('correct');
    } else {
      $('input').addClass('incorrect');
    }
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;span data-answer="text2"&gt;
    &lt;input type="text" id="A"&gt;
  &lt;/span&gt;
  
  &lt;span data-answer="text1"&gt;
    &lt;input type="text" id="B"&gt;
  &lt;/span&gt;
  
  &lt;button class="submit"&gt;Check Answer&lt;/button&gt;</code></pre>
  </div>
  </div>
  </p>