title: Most efficient way to select all elements with an array of values
body: <p>Let's suppose I have a <code>&lt;select&gt;</code> element:</p>
  
  <pre><code>&lt;select id="foobar" name="foobar" multiple="multiple"&gt;
      &lt;option value="1"&gt;Foobar 1&lt;/option&gt;
      &lt;option value="2"&gt;Foobar 2&lt;/option&gt;
      &lt;option value="3"&gt;Foobar 3&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>And let's suppose I have an array of values, something like:</p>
  
  <pre><code>var optionValues = [2, 3];
  </code></pre>
  
  <p>How can I select the <code>&lt;option&gt;</code>s with values 2 and 3 most efficiently?</p>
  
  <p>I'm working with a <code>&lt;select&gt;</code> that has thousands of <code>&lt;option&gt;</code>s, so doing it manually like this won't work:</p>
  
  <pre><code>var optionElements = [];
  
  $("#foobar").children().each(function() {
      if($.inArray($(this).val(), optionValues)) {
          optionElements.push($(this));
      }
  }
  </code></pre>
  
  <p>It's just too slow. Is there a way to hand jQuery a list of values for the elements I need to select? Any ideas?</p>
  
  <p>P.S. In case you're wondering, I am in the middle of optimizing my <a href="http://code.google.com/p/jquery-ui-picklist/" rel="nofollow">jQuery PickList widget</a> which currently <a href="http://code.google.com/p/jquery-ui-picklist/issues/detail?id=6" rel="nofollow">sucks at handling large lists</a>.</p>