When the script runs, the document probably hasn't been drawn yet.
Try this:
var dateFormat = "M/D/YYYY, h:mm A";
$( document ).ready(()=>{
$('.datepicker').each(function(i, e) {
new Pikaday({
field: e,
format: dateFormat,
disableDayFn: function (date) {
return moment(date).isAfter(new Date());
},
onOpen: function() {
if (!this._o.field.value) {
this.setDate(new Date());
}
}
});
$(e).on('change', function(ev) {
onDatePickerSelect(ev);
});
});
});
function setDateOnLoad() {
$("#dateFromTimestamp").each(function(i, e) {
new Pikaday({
field: e,
format: dateFormat,
value: new Date(1488484260000)
});
});
}
this will ensure that the code runs only after the doc is drawn