title: Find previous and next images in div with JQuery
body: <p>I need to find the next and previous image starting from the img with the 'active' class within a div. The problem is, the search for the previous and next image always return a length of 0, so nothing happens.</p>
  
  <pre><code>&lt;style&gt;
  .container #left img{
  display:hidden;
  }
  
  .container #left img.active{
  display:block;
  }
  &lt;/style&gt;
  
  &lt;div class="container"&gt;
  
  &lt;div id="left"&gt;
  
  &lt;img src="1.jpg" /&gt;
  &lt;img src="2.jpg" /&gt;
  &lt;img src="3.jpg" /&gt;
  &lt;img src="4.jpg" /&gt;
  &lt;img src="5.jpg" /&gt;
  
  &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;div class="arrow-left"&gt;&lt;/div&gt;
  &lt;div class="arrow-right"&gt;&lt;/div&gt;
  
  &lt;script&gt;
  $('.container #left img:first-child').addClass('active');
  
      $(document).off('click', '.arrow-left').on('click', '.arrow-left', function() {
          var prev = $('.container #left img.active').closest('div').prev().find('img');
          if (prev.length == 0) {
              prev = $('.container #left img:last');
          }
          $('.container #left img').removeClass('active');
          prev.addClass('active');
      });
  &lt;/script&gt;
  </code></pre>