A more efficient way to orient a child on loading

In many cases, I use jQuery awesome datepicker in forms. I need a general way to apply it without knowing what the identifier or input class will be. I came up with this:

<span id="datePickerChild">
 <input type="text"/>
</span>
<script type="text/javascript">
 $(document.getElementById("datePickerChild").firstChild).datepicker();
</script>

Using the mvc3 structure, this input is inserted with their own identifiers, etc. Helper-based runtimes, so I need this dynamic approach. Is there a more efficient way to do this?

Edit:

Using jQuery 1.4.4

+3
source share
2 answers

This seems like a reasonable approach for this. Perhaps you could do this a little more "idiomatically" with jQuery, as shown below:

$('#datePickerChild').children().first().datepicker();

Or even:

$('#datePickerChild > input:first').datepicker();

, , , , , . " " ( ), . , - :

$('.date-picker-container').children().first().datepicker();
+2

, , , , , , ? - :

$("[id*=datePicker]").datepicker();
+1

All Articles