JDoe JDoe - 4 months ago 16
Javascript Question

Datepicker does not show at first click

I've just created a simple

textbox
where inside I binded the
.click
event to show the
Datepicker
, anyway, seems that at first click the
Datepicker
can't show, but if I click outside the control and then click again over the
textbox
I can see the
Datepicker
, I wonder why happen this?

Check out my code here:

<input type="text" id="calendar" placeholder="calendar">

$(function()
{
$('#calendar').click(function()
{
$(this).datepicker();
});
});


FIDDLE.

Answer

You are initializing Date picker on your text box click. You have to initialize on document ready method if you want to Open date picker immediate after page load

Change your initializing code to

$(function()
{
    $('#calendar').datepicker();
});

For your reference fiddler updated