title: Check for existence of classes on click (React)
body: <p>I want to check to see if a particular element, when clicked, has a specified class. I know that you can bind a click handler which passes <code>e.target</code> to the handler. My thinking was to get <code>e.target.classList.indexOf(this.myClass) &gt; -1</code> to see if it has the class, but I get the following error.</p>
  
  <blockquote>
    <p>e.target.classList.indexOf is not a function</p>
  </blockquote>
  
  <p>I assume this is because <code>classList</code> is an <em>array-like</em> object, and not an actual array. Is there a simpler way to get a list of classes from a clicked element in React without performing all of the "slice call" magic?</p>
  
  <pre><code>class MyComponent extends React.Component {
      constructor(props) {
          super(props);
          this.myClass = 'my-class';
      }
  
      handleClick(e) {
          // check if e.target class has this.myClass
          if (/* logic */) {
              // perform action
          }
      }
  
      render() {
          return &lt;div onClick={this.handleClick.bind(this)} className={this.myClass + ' other-class'}&gt;
              &lt;div&gt;My Component&lt;/div&gt;
          &lt;/div&gt;
      }
  
  }
  </code></pre>
  
  <p><strong>How can I get an array of classes from the "target" element of a click in React's event system?</strong></p>