title: What's the performance benefit of assigning JQuery object to a variable?
body: <p>Somebody saw me using the following JQuery code:</p>
  
  <pre><code>function showAll(){
      $(".button").show();
  }
  function hideAll(){
      $(".button").hide();
  }
  </code></pre>
  
  <p>And he said that this was a waste of resources. That I should first assign <code>$(".button")</code> to a variable, and then perform the <code>show()</code> and <code>hide()</code> methods on this variable like this:</p>
  
  <pre><code>var allButtons = $(".button");
  function showAll(){
      allButtons.show();
  }
  function hideAll(){
      allButtons.hide();
  }
  </code></pre>
  
  <p>Both versions work, but what is the performance benefit to this? I believe the benefit is negligible and, moreover, cumbersome because now you have another level of separation between the class name and the variable you're modifying, but does he have a valid point? Is one of the two considered best practice?</p>