title: looping through elements with jQuery based on name attribute rather than id
body: <p>Thanks for taking the time to read this.</p>
  
  <p>I have an unknown number of (dynamically inserted) input elements in a form, to each of which I want to attach the datepicker widget included in jQuery UI.</p>
  
  <p>All of the input elements that I want to attach the datepicker to have a class of "date-pick". Obviously because we have more than one matching element we need more than just a class name so that the date value gets returned to the originating field rather than just the first match.</p>
  
  <p>Ordinarily I'd probably just do something like:</p>
  
  <pre><code>$("input.date-pick").each(function(){
      $(this).datepicker({dateFormat: "yy-mm-dd"});
  });
  </code></pre>
  
  <p><strong>However in the code I'm working with, the input elements do not have unique IDs until the form data is saved</strong> (something that I'm unable to change), though they do have unique name attribute values of the format <code>name="field_id_x[y][z]"</code> which, when the form is saved then gets converted to an id of the format <code>id="field_id_xyz"</code>.</p>
  
  <p>So my question is, can anyone show me how to loop through all the input elements with a class of "date-pick" based on their name attribute values?</p>
  
  <p>(PS It might also be worth mentioning that the number of matching input elements in the form can be increased/decreased by the user on the fly.)</p>