title: Passing jquery selector to sub-function within a plugin
body: <p>I'm trying to make a quick jquery plugin (as a learning exercise) for making a simple pager from a list of items (LIs in this case) and have run into a problem when passing the current selector (this) to a sub-function.  The code is below.</p>
  
  <p>The problem is when creating the dynamic nav (the plugin requires jquery 1.3) and I need to pass the selector, as it is the sub-function that does the actual showing/hiding that make up the pager.  I'm trying the following</p>
  
  <pre><code>var selector = $(this);
  </code></pre>
  
  <p>To get the selector, then passing it to the sub-function at the bottom of the script as follows</p>
  
  <pre><code>$(".pageNav a").live("click", function(selector) {
  </code></pre>
  
  <p>and hoping to use the selector within the subfunction as follows</p>
  
  <pre><code>$(selector).hide();
  </code></pre>
  
  <p>But i'm getting nothing.  Any advice would be appreciated, no need to finish the plugin for me!</p>
  
  <p>Thanks</p>
  
  <pre><code>(function($) {
  $.fn.quickPager = function() {
  
      //edit this
      var pageSize = 10;
      //leave this
      var selector = $(this);
      var totalRecords = $(this).length;
      var currentPage = 1;
      var pageCounter = 1;
  
      $(this).each(function(i){
          if(i &lt; pageCounter*pageSize &amp;&amp; i &gt;= (pageCounter-1)*pageSize) {
              $(this).addClass("page"+pageCounter);
          }
          else {
              $(this).addClass("page"+(pageCounter+1));
              pageCounter ++;
          }   
      });
  
      //show/hide the appropriate regions 
      $(this).hide();
      $(".page"+currentPage).show();
  
      //first check if there is more than one page. If so, build nav
      if(pageCounter &gt; 1) {
  
          //Build pager navigation
          var pageNav = "&lt;ul class='pageNav'&gt;";   
          for (i=1;i&lt;=pageCounter;i++){
  
              if (i==1) {
                  pageNav += "&lt;li class=currentPage pageNav"+i+"'&gt;&lt;a rel='"+i+"' href='#'&gt;Page "+i+"&lt;/a&gt;&lt;/li&gt;";   
              }
              else {
                  pageNav += "&lt;li class='pageNav"+i+"'&gt;&lt;a rel='"+i+"' href='#'&gt;Page "+i+"&lt;/a&gt;&lt;/li&gt;";
              }
  
          }
          pageNav += "&lt;/ul&gt;";
          $("#pagerContainer").append(pageNav);
  
          //pager navigation behaviour
          $(".pageNav a").live("click", function(selector) {          
              //grab the REL attribute 
              var clickedLink = $(this).attr("rel");
              currentPage = clickedLink;
              //remove current current (!) page
              $("li.currentPage").removeClass("currentPage");
              //Add current page highlighting
              $(this).parent("li").addClass("currentPage");
              //hide and show relevant links
              //$("ul.paging li").text("TEST");
              $(selector).hide();
              $(selector+".page"+clickedLink).show();
              return false;
          });
  
      }
  
  
  
  }
  })(jQuery);
  </code></pre>