actually you don't need to replace this all....
there are 2 ways to do this. One is to use autoclose property, the other (alternativ) way is to use the on change property thats fired by the input when selecting a Date.
HTML
<div class="container">
<div class="hero-unit">
<input type="text" placeholder="Sample 1: Click to show datepicker" id="example1">
</div>
<div class="hero-unit">
<input type="text" placeholder="Sample 2: Click to show datepicker" id="example2">
</div>
</div>
jQuery
$(document).ready(function () {
$('#example1').datepicker({
format: "dd/mm/yyyy",
autoclose: true
});
//Alternativ way
$('#example2').datepicker({
format: "dd/mm/yyyy"
}).on('change', function(){
$('.datepicker').hide();
});
});
this is all you have to do :)
HERE IS A FIDDLE to see whats happening.
Fiddleupdate on 13 of July 2016: CDN wasnt present anymore
According to your EDIT:
$('#example1').datepicker().on('changeDate', function (ev) {
$('#example1').Close();
});
Here you take the Input (that has no Close-Function) and create a Datepicker-Element. If the element changes you want to close it but you still try to close the Input (That has no close-function).
Binding a mouseup event to the document state may not be the best idea because you will fire all containing scripts on each click!
Thats it :)
EDIT: August 2017 (Added a StackOverFlowFiddle aka Snippet. Same as in Top of Post)
$(document).ready(function () {_x000D_
$('#example1').datepicker({_x000D_
format: "dd/mm/yyyy",_x000D_
autoclose: true_x000D_
});_x000D_
_x000D_
//Alternativ way_x000D_
$('#example2').datepicker({_x000D_
format: "dd/mm/yyyy"_x000D_
}).on('change', function(){_x000D_
$('.datepicker').hide();_x000D_
});_x000D_
});
_x000D_
.hero-unit{_x000D_
float: left;_x000D_
width: 210px;_x000D_
margin-right: 25px;_x000D_
}_x000D_
.hero-unit input{_x000D_
width: 100%;_x000D_
}
_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>_x000D_
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>_x000D_
<div class="container">_x000D_
<div class="hero-unit">_x000D_
<input type="text" placeholder="Sample 1: Click to show datepicker" id="example1">_x000D_
</div>_x000D_
<div class="hero-unit">_x000D_
<input type="text" placeholder="Sample 2: Click to show datepicker" id="example2">_x000D_
</div>_x000D_
</div>
_x000D_
EDIT: December 2018 Obviously Bootstrap-Datepicker doesnt work with jQuery 3.x see this to fix