title: JQuery Get Next first element class name
body: <pre><code>var cName = ($(".myclass").next().attr('class'));
  alert(cName);
  
  if (cName == "c1") {
  
  $("#Output").addClass("green");
  $("#Output").removeClass("red");
  
  } else {
  
  $("#Output").addClass("red");
  $("#Output").removeClass("green");
  }
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;p class="myclass"&gt;If you click on me, I will disappear.
  &lt;span class="c1"&gt;&lt;/span&gt;
  &lt;span class="c2"&gt;&lt;/span&gt;
  &lt;span class="c3"&gt;&lt;/span&gt;
  &lt;span class="c4"&gt;&lt;/span&gt;
  &lt;div class="d1"&gt;&lt;/div&gt;
  &lt;div class="d2"&gt;&lt;/div&gt;
  &lt;div id="Output" style="width:25px; height:25px;"&gt;&lt;/div&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I am trying to get the <code>.classname</code> of the first <code>span</code> element. Why is jquery not fetching the next <code>span</code> element <code>.classname</code> ? Please help.</p>