title: jQuery .next - Add a Class to next Element
body: <p>i'm trying to change on click the class of the div's inside the container and create a loop. But with the .next selector the class is applied to all elements.</p>
  
  <p>The jQuery-Code:</p>
  
  <pre><code>$(document).ready(function(){
      $( "#link" ).click(function() {
          if ( $( ".inhalt" ).hasClass( "active" )) {
              if ( $( ".inhalt" ).last().hasClass( "active" )) {
                  $( ".inhalt" ).removeClass('active');
                  $( ".inhalt" ).first().addClass('active');
                  return;
              }   
              $( ".inhalt" ).prev().removeClass('active');
              $( ".inhalt" ).next().addClass('active');
          }
          else {
              $( ".inhalt" ).first().addClass('active');
          }
      });
  });
  </code></pre>
  
  <p>The HTML:</p>
  
  <pre><code>&lt;div id="container"&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;1&lt;/a&gt; &lt;/div&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;2&lt;/a&gt; &lt;/div&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;3&lt;/a&gt; &lt;/div&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;4&lt;/a&gt; &lt;/div&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;5&lt;/a&gt; &lt;/div&gt;
     &lt;div class="inhalt"&gt;&lt;a href="#"&gt;6&lt;/a&gt; &lt;/div&gt;
  &lt;/div&gt;
  &lt;div&gt;&lt;a href="#" id="link"&gt;hier&lt;/a&gt;&lt;/div&gt;
  </code></pre>
  
  <p>Thanks in advance for your help!
  Alex</p>