0

Im trying to use a jQuery datepicker to select a date, but when I click in the text box, the datepicker does not display.

HTML:

<link href="http://code.jquery.com/ui/1.10.4/themes/ui-lightness/jquery-ui.css" rel="stylesheet">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

<script>
$(function() {
    $( "#date" ).datepicker();
});
</script>

<body>
    <p>Date: <input type="text" id="date"></p>
</body>

Also, when I inspect the element, it shows up as having a class of hasDatepicker

5
  • 1
    Your code seems fine (jsfiddle.net/j08691/syvff3ek). Any errors in the console? Commented Mar 10, 2015 at 16:54
  • No errors at all. I am using this form in a google map infowindow which uses clone() to display the map. Would this maybe be causing a problem with it? Commented Mar 10, 2015 at 16:56
  • Put the scripts after the Body tags Commented Mar 10, 2015 at 16:59
  • Putting the scripts outside the body does nothing Commented Mar 10, 2015 at 17:02
  • I'd stay away from ids here. Use a class. See this answer stackoverflow.com/questions/707603/… If clone is giving you issues, see this answer stackoverflow.com/questions/10433154/… Commented Mar 10, 2015 at 17:27

2 Answers 2

1

If your code is indeed executing after the DOM has fully loaded and that is NOT the problem...

Try to remove the .hasDatepicker before executing.

If it's chainable

$("#date").removeClass("hasDatepicker").datepicker();

Otherwise

$("#date").removeClass("hasDatepicker");
$("#date").datepicker();
Sign up to request clarification or add additional context in comments.

Comments

0

Your script is likely running before the DOM has fully loaded.

You want to make sure your jQuery executes when the page is ready:

$(document).ready(function() {
  // Run your code here
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.