title: D3.js check to see if a node has a class
body: <p>I'm trying to write a <code>click</code> function to select the next <code>g.slice</code> node, add a class of <code>.sliceActive</code> to it and remove <code>.sliceActive</code> from the original <code>.slice</code>. However, only when you are at the last <code>g.slice</code> (with a class of <code>.slice5</code>) you would add the <code>.sliceActive</code> to the the first <code>g.slice</code> with a class of <code>.slice0</code>.</p>
  
  <p>This is what I have so far that is not working. I think the problem is I don't know how to see if the current <code>.sliceActive</code> node also has the class of <code>.slice5</code>.</p>
  
  <pre><code>        $(".next").click(function(){
              var nextSlice;
              if(d3.select("g.sliceActive").hasClass("slice5")){
                  nextSlice= d3.select(".slice0");
              }else{
                  nextSlice= d3.select("g.sliceActive + g");
              }               
              d3.select("g.sliceActive").classed("sliceActive",false);
              nextSlice.classed("sliceActive",true);
          });
  </code></pre>
  
  <p>And here is how it looks in the web inspector:
  <img src="https://i.stack.imgur.com/6rWN8.png" alt="enter image description here"></p>