title: Display prev item when next clicked Json+JS+Jquery
body: <p>I have this function to display blog entry:</p>
  
  <pre><code> function getPrev(item, articles) {
     for (var i = 0, len = articles.length; i &lt; len; i++) {
        if (articles[i].id === item) {
            return (i - 1 &gt;= 0) ? articles[i - 1] : null;
        }
     }
     return null;
   }
  </code></pre>
  
  <p>And this one: </p>
  
  <pre><code>  function getNext(item, articles) {
       for (var i = 0, len = articles.length; i &lt; len; i++) {
          if (articles[i].id === item) {
            return (typeof (articles[i + 1]) !== 'undefined') ? articles[i + 1] : null;
          }
       }
       return null;
     }
  </code></pre>
  
  <p>And finally ajax call:</p>
  
  <pre><code>  function getArticle(which) {
  $.ajax({
      type: "GET",
      url: "../Content/test.txt",
      dataType: "json",
      success: function (data) {
          var entry;
          var id = parseInt(document.getElementById('blogcont').getAttribute('data-id')) || 0;
  
          if (which === 'next') {
              entry = getNext(id, data);
          } else if (which === 'prev') {
              entry = getPrev(id, data);
          } else {
              entry = data[0];
          }
  
          if (entry) {
              document.querySelector('#blogcont .headline').innerHTML = entry.Title;
              document.querySelector('#blogcont .content').innerHTML = entry.Content;
              document.getElementById('blogcont').setAttribute('data-id', entry.id);
          }
      },
      error: function (data) {
          console.error('Error in AJAX call');
          console.error(data);
      }
  });
  }
  </code></pre>
  
  <p>I want to display previous one in left side panel (similar) while current is displayed. Any ideas?My html:
       
                  
                     
                     </p> 
                  </p>
  
  <pre><code>            &lt;button class="nvgt" id="prev"&gt;Previous&lt;/button&gt;            
              &lt;button class="nvgt" id="next"&gt;Next&lt;/button&gt;
          &lt;/div&gt;
          &lt;div id="articles"&gt;
              &lt;div id="similar" class="box"&gt;&lt;/div&gt;
              &lt;div id="popular" class="box"&gt;&lt;/div&gt;
              &lt;div id="thisblog" class="box"&gt;&lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Thanks</p>