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="nofollow noreferrer noopener" 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
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
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.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0