Javascript action on click
<p>I have few generated text fields. I want to show datepicker on text field click.</p>

<pre><code>&lt;!-- text fields --&gt;
&lt;input id="id_validity_set-0-valid_until" name="validity_set-0-valid_until" type="text" /&gt;
&lt;input id="id_validity_set-1-valid_until" name="validity_set-1-valid_until" type="text" /&gt;
&lt;input id="id_validity_set-2-valid_until" name="validity_set-2-valid_until" type="text" /&gt;

&lt;!-- jquery code --&gt;
$(document).on("click", "input[type='text']", function() {
  $( this ).datepicker({ dateFormat: 'yy-mm-dd ' });
});
</code></pre>

<p>When I click first time, nothing happens but if I click second time into text field datepicker shows itself. How to make datepicker show on first click? Thanks</p>