title: jquery .prev() strange behavior
body: <p>I have a very simple list of LI's and they are all on the same level (nothing nested) I want to find the previous element of any element who's class is level1. For some reason prev() is failing on items when the 'level1' element is more than one sibling away. I don't want to use prevAll() because I only want the closest li that comes before my element and has a class of level1. </p>
  
  <pre><code>&lt;ul id="main-list"&gt;
      &lt;li class="level1" data-id="1" data-parent="none" id="recordsArray_1"&gt;Overview&lt;/li&gt;
      &lt;li class="level2" data-id="4" data-parent="Overview" id="recordsArray_4"&gt;Benefits&lt;/li&gt;
      &lt;li class="level2" data-id="2" data-parent="undefined" id="recordsArray_2"&gt;Core Concepts&lt;/li&gt;
      &lt;li class="level2" data-id="3" data-parent="undefined" id="recordsArray_3"&gt;Access&lt;/li&gt;
      &lt;li class="level3" data-id="5" data-parent="Access" id="recordsArray_5"&gt;Onboarding&lt;/li&gt;
      &lt;li class="level1" data-id="12" data-parent="none" id="recordsArray_12"&gt;test top&lt;/li&gt;
      &lt;li class="level2" data-id="10" data-parent="test top" id="recordsArray_10"&gt;test 1&lt;/li&gt;
      &lt;li class="level2" data-id="14" data-parent="undefined" id="recordsArray_14"&gt;New Access&lt;/li&gt;
      &lt;li class="level3" data-id="13" data-parent="New Access" id="recordsArray_13"&gt;test 2&lt;/li&gt;
      &lt;li class="level1" data-id="6" data-parent="none" id="recordsArray_6"&gt;Underview&lt;/li&gt;
      &lt;li class="level2" data-id="7" data-parent="Underview" id="recordsArray_7"&gt;coolpage1&lt;/li&gt;
      &lt;li class="level3" data-id="9" data-parent="coolpage1" id="recordsArray_9"&gt;page level 3&lt;/li&gt;
  &lt;/ul&gt;
  
  &lt;script&gt;
  var publishList = $('#main-list li');
  
  $.each(publishList, function () {
      var thisClass = $(this).attr('class');
      var parentID = $(this).attr('data-parent');
      var recordID = $(this).attr('data-id');
  
      if (thisClass == 'level2') {
          var thisParent = $(this).prev('.level1').html();
          console.log(this);    
      }
  }); 
  &lt;/script&gt;
  </code></pre>
  
  <p>console output: </p>
  
  <pre><code>Overview
  undefined
  undefined
  test top
  undefined
  Underview
  </code></pre>
  
  <p>What am I doing wrong? I expected prev() to return overview for core concepts, access and New Access but they are coming back undefined. Is there a flaw in my logic?</p>