title: Generate page numbers using javascript/jquery?
body: <p>How to generate page numbers like the below using javascript/jquery?</p>
  
  <p>If the 5 th page is selected i have to show 3,4 and 6,7 and also 1,last page with prev,next...
  Any suggestion....</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>How to work with json data that use these pagination div? (ie) My json data contains 50 records
  I want to 10 in page 1 and so on... How to paginate json data with these numbers...</p>
  
  <p>I want a jquery function to pass <code>currentpageno,lastpagenumber</code> and the function should generate me page numbers like the below for me </p>
  
  <p>If it is the first page</p>
  
  <p><a href="https://i.stack.imgur.com/BtvYz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BtvYz.jpg" alt="istpage"></a>
  </p>
  
  <p>If it is in the middle,</p>
  
  <p><a href="https://i.stack.imgur.com/GrXYu.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GrXYu.jpg" alt="Pager"></a>
  </p>
  
  <p>If it is the last page,</p>
  
  <p><a href="https://i.stack.imgur.com/F1iRN.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/F1iRN.jpg" alt="lastpage"></a>
  </p>
  
  <p><strong>Second EDIT:</strong></p>
  
  <p>I have tried this function but doesn't seem to get the desired result </p>
  
  <pre><code>function generatePages(currentPage, LastPage) {
      if (LastPage &lt;= 5) {
          var pages = '';
          for(var i=1;i&lt;=5;i++)
          {
              pages += "&lt;a class='page-numbers' href='#'&gt;" + i + "&lt;/a&gt;"
          }
          $("#PagerDiv").append(pages);
      }
      if (LastPage &gt; 5) {
          var pages = '';
          for (var i = 1; i &lt;= 5; i++) {
              pages += "&lt;a class='page-numbers' href='#'&gt;" + i + "&lt;/a&gt;"
          }
          $("#PagerDiv").append(pages);
      }
  }
  </code></pre>
  
  <p>I have the <code>lastPage</code> and <code>currentPage</code> values please help me out getting this...</p>