title: How to declare variables in jQuery the right way
body: <p>I have this jQuery code that works in fiddle but not on my website!</p>
  
  <p>I am working on this jQuery framework</p>
  
  <pre><code>https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js?ver=4.4.2
  </code></pre>
  
  <p>but it seems the variables are not declared properly according to console.log in Fox &amp; I am getting the following error in Chrome.</p>
  
  <p><em>Undefined variable: pagination
  Undefined variable: lis
  Undefined variable: next
  Undefined variable: toHighlight
  Undefined variable: prev</em></p>
  
  <pre><code>$(document).ready(function () {
      var $pagination = $('.qpagination');
      var $lis = $pagination.find('li:not(#qprev, #qnext)');
      $lis.filter(':gt(4)').hide();
      $lis.filter(':lt(5)').addClass('active');
  
      var $next = $('#qnext').click(function () {
          var idx = $lis.index($lis.filter('.active:last')) || 0;
  
          var $toHighlight = $lis.slice(idx + 1, idx + 6);
          if ($toHighlight.length == 0) {
              $prev.show();
              return;
          }
  
          $next.show();
          $lis.filter('.active').removeClass('active').hide();
          $toHighlight.show().addClass('active')
      });
  
      var $prev = $('#qprev').click(function () {
          var idx = $lis.index($lis.filter('.active:first')) || 0;
  
          var start = idx &lt; 4 ? 0 : idx - 4;
          var $toHighlight = $lis.slice(start, start + 5);
          if ($toHighlight.length == 0) {
              $prev.hide();
              return;
          }
  
          $next.show();
          $lis.filter('.active').removeClass('active').hide();
          $toHighlight.show().addClass('active')
      });
  });
  </code></pre>
  
  <p>This a <a href="https://jsfiddle.net/moerayan/o3das45q/3/" rel="nofollow">demo</a> of the code on Fiddle. it works fine on Fiddle though!</p>
  
  <p>And here is the <a href="http://gulf-brokers.com" rel="nofollow">website</a> I am working on (Click on Leave me a comment box)</p>