title: how to judge an element's previous or next element exist with jquery?
body: <p>suppose I have an <code>&lt;ul&gt;</code>
  :</p>
  
  <pre><code>&lt;ul&gt;
      &lt;li&gt;&lt;/li&gt;
      &lt;li&gt;&lt;/li&gt;
      &lt;li class="test"&gt;&lt;/li&gt;
  &lt;/ul&gt;
  </code></pre>
  
  <p>How can I judge the <code>.test</code> have its next element with jquery ?
  like this?:</p>
  
  <pre><code>if ($("li.test").next()) { …… }
  </code></pre>
  
  <p>the strange thing is that ,even I write like above:</p>
  
  <pre><code>if ($("li.test").next()) {alert("true");}
  </code></pre>
  
  <p>it still alert "true",but as you see,there is no element next to it ?why this happened?</p>
  
  <p>Or what I can do is </p>
  
  <pre><code>        for (i = 0; i &lt; $("li").length; i++) {
              if ($("li").eq(i).hasClass("test")) {
                  if (i == $("li").length - 1) {
                      alert("true");
                  }
              }
          }
  </code></pre>
  
  <p>presently this could solve my problem,but is there a easy way?</p>
  
  <p>thank you</p>