title: How to iterate through DOM elements in react and add/remove classes?
body: <p>I am beginner to react and I am unable to iterate through <code>div</code> elements.<br> Each of these <code>div</code> elements (shown in the code) have a common <code>className="step"</code> initially but once the button <code>Next</code> is clicked I want 1st div to have <code>className="step current"</code> .
  Once <code>Next</code> is clicked again 1st div element should have <code>className="step done"</code>(remove current and append done) and 2nd div element would have <code>classname="step current"</code></p>
  
  <p>I was able to toggle the className from <code>"step"</code> to <code>"step current"</code> in the following code but I am facing difficulty to traverse the div elements and add or remove the class.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>class NavBar extends React.Component{
      state = {
          addClass : false
      }
      handleClick=()=&gt;{
          this.setState({addClass: !this.state.addClass});
      }
      render(){
          let arrowClass = ["step"];
          if(this.state.addClass){    
              arrowClass.push("current");
          }
          return(
              &lt;div id="navbar-div"&gt;
                  &lt;div className="arrow-steps clearfix"&gt;
               1.       &lt;div className={arrowClass.join(' ')}&gt;
                          &lt;span&gt; Step1&lt;/span&gt;
                      &lt;/div&gt;
               2.       &lt;div className={arrowClass.join(' ')}&gt;
                          &lt;span&gt;Step2&lt;/span&gt;
                      &lt;/div&gt;
               3.       &lt;div className={arrowClass.join(' ')}&gt;
                          &lt;span&gt; Step3&lt;/span&gt;
                      &lt;/div&gt;
               4.       &lt;div className={arrowClass.join(' ')}&gt;
                          &lt;span&gt;Step4&lt;/span&gt;
                      &lt;/div&gt;
               5.       &lt;div className={arrowClass.join(' ')}&gt;
                          &lt;span&gt;Step5&lt;/span&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div className="nav clearfix"&gt;
                      &lt;a href="#" className="prev"&gt;Previous&lt;/a&gt;
                      &lt;a href="#" className="next pull-right" onClick={this.handleClick}&gt;Next&lt;/a&gt;
                  &lt;/div&gt;
                  &lt;/div&gt;
          );
      }
  }
  
  ReactDOM.render(
    &lt;NavBar /&gt;,
    document.getElementById("root")
  );</code></pre>
  <pre class="snippet-code-css lang-css prettyprint-override"><code>.current {
    font-weight: bold;
  }
  .done {
    color: #aaa;
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div id="root"&gt;&lt;/div&gt;
  
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.2/umd/react.production.min.js"&gt;&lt;/script&gt;
  &lt;script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.2/umd/react-dom.production.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The classes <code>step, current and done</code> are defined in the css file.</p>