Bootstrap Datepicker Not Working

15,796

It looks like you're trying to initialize a datepicker when there's no #datepicker element in DOM yet (the corresponding input follows <script> element, not vice versa).

As $('#datepicker') will still return a jQuery-wrapped object (not null!), no error will be thrown.

To solve this, either make this call when DOM is loaded:

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

or move this script into very end of <body> element.

I'd choose the first option; moving all the DOM-ready actions into the same $(function() { ... }); wrapper as well.

Share:
15,796
Bob
Author by

Bob

Updated on June 13, 2022

Comments

  • Bob
    Bob almost 2 years

    I am trying to get bootstrap datepicker to work but it does not even show up.
    http://www.eyecon.ro/bootstrap-datepicker/

    <link href="~/Css/datepicker.css" rel="stylesheet" />
    <script src="~/Scripts/jquery-1.8.1.js" type="text/javascript"></script>
    <script src="~/Scripts/bootstrap-datepicker.js" type="text/javascript"></script>
    <script type="text/javascript">
        $("#datepicker").datepicker();
    </script>
    
    <input id="datepicker" value="10/22/2011" />
    

    I am using bootstrap 2.1.1

  • Jeevanantham
    Jeevanantham about 9 years
    tired loading object on document load but still its not working