title: Check if active element has particular class via javascript
body: <p>I'm writing a single-field form and want the Enter key to advance the form to the next input field. Since there's another form on the page, I only want the Enter key to advance the form when one of the inputs in that form is the <code>activeElement</code>.</p>
  
  <p>I've achieved this with what seems like an extremely verbose <code>if()</code> statement here:</p>
  
  <pre><code>document.addEventListener( 'keydown', function( ev ) {
          var keyCode = ev.keyCode || ev.which;
          var ids = [ 'this', 'that', 'there', 'thing', 'other' ];
          if ( document.getElementById( ids[0] ) === document.activeElement || document.getElementById( ids[1] ) === document.activeElement || document.getElementById( ids[2] ) === document.activeElement || document.getElementById( ids[3] ) === document.activeElement || document.getElementById( ids[4] ) === document.activeElement) {
              if( keyCode === 13 ) {
                  ev.preventDefault();
                  self._nextQuestion();
              }
          }
      } );
  </code></pre>
  
  <p>Each of the inputs are the same class: <code>.questions</code>. I've tried something like:</p>
  
  <pre><code>document.addEventListener( 'keydown', function( ev ) {
      var keyCode = ev.keyCode || ev.which;
      var ids = [ 'this', 'that', 'there', 'thing', 'other' ];
      if ( document.querySelector('.questions') === document.activeElement) {
          if( keyCode === 13 ) {
              ev.preventDefault();
              self._nextQuestion();
          }
      }
  } );
  </code></pre>
  
  <p>But of course, this only accesses the first instance of <code>.questions</code> on the page. I don't want to iterate over nodes, as it doesn't seem much better than what I have already.</p>
  
  <p>I'm a novice, and I'm looking for more concise logic.</p>