Have to click twice to initiate datepicker. Alert solves it. Why?

Have to click twice to initiate datepicker. Alert solves it. Why?

Hello..
I have trouble with datepicker and I dont understand it. This is my code:

  1. $("#mytextbox").click(function(){
  2.   $("#mytextbox").datepicker();
  3. })

If I want to show calendar for the first time I have to click three times. First click to the textbox, second one anywhere else and third click again to textbox. But if I write this:

  1. $("#mytextbox").click(function(){
  2.   $("#mytextbox").datepicker();
  3.   alert("useless alert");
  4. })
... calendar appears after the first click to the textbox when the alert window is closed.

Does anybody know why?

I tried to solve it using bind / unbind functions, but did not succeed.