Datepicker load

Datepicker load

Hi,

Why does a datepicker only load from a jquery function and not from a javascript function?

Example:

<script>
test();
function test() {
      $('#datepicker').datepicker(); //Datepicker doesn't load but the function is called
}
</script>

//This works
<script>
$(function() {
      $('#datepicker').datepicker(); //Datepicker is loaded
</script>