title: Does jQuery do any kind of caching of "selectors"?
body: <p>For example, will the first piece of code perform a full search twice, or is it smart enough to cache results if no DOM changes have occurred?</p>
  
  <pre><code>if ($("#navbar .heading").text() &gt; "") {
    $("#navbar .heading").hide();
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>var $heading = $("#navbar .heading");
  
  if ($heading.text() &gt; "") {
    $heading.hide();
  }
  </code></pre>
  
  <p>If the selector is more complex I can imagine it's a non-trivial hit.</p>