title: Custom jQuery Selector
body: <p>Quick question - is it possible to extend jQuery selectors to change the resultset (for example) via traversal instead of just by filtering an existing set?</p>
  
  <p>To clarify - I don't want the selector equivalent of a call to <code>$.filter()</code> - I want something closer to <code>$('foo:nth-child(n)')</code> or <code>$('foo:eq(n)')</code>, where I can specify exactly which elements are returned by the selector.  Any thoughts would be appreciated.</p>
  
  <p>Edit: here's an example of what I want to implement:</p>
  
  <pre><code>$.expr[':']['nth-parent'] = function(deTarget, iIndex, aProperties, aStack) {
      var iN, $currentElement;
  
      if(!deTarget)
          return;
      if(!aProperties || aProperties.length &lt; 4 || isNaN(iN = parseInt(aProperties[3])) || iN &lt; 0)
          throw('jQuery.nth-parent(N) requires a non-negative integer argument');
  
      $currentElement = $(deTarget);
      while(--iN &gt;= 0)
          $currentElement = $currentElement.parent();
  
      aStack = $currentElement.length ? [$currentElement.get(0)] : [];
      return aStack.length ? true : false;
  };
  </code></pre>
  
  <p>So, ultimately, I'd want the new <code>aStack</code> array returned as the result set, in this particular case.</p>