'Uncaught TypeError: $(...).datetimepicker is not a function when I call it in js function
I am trying to change option of datetimepicker when I call a function but i'm getting the error "Uncaught TypeError: $(...).datetimepicker is not a function" when the datetimepicker is inside of the function refresh. What's the problem ?
Here is the code :
<script src="~/Content/vendor/jquery/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="~/Content/vendor/datepicker/moment.js"></script>
<script type="text/javascript" src="~/Content/vendor/datepicker/tempusdominus-bootstrap-4.js"></script>
<link rel="stylesheet" href="~/Content/vendor/datepicker/tempusdominus-bootstrap-4.css" />
<script type="text/javascript">
$('#representant_date_dem' + 1).datetimepicker({ format: 'DD/MM/YYYY', date: moment() }); //working
function refresh(i) {
var id = document.getElementById('myTableDeplacementPrestation').rows.length;
for (var j = i; j <= id; j++) {
if ($('#representant_date_dem' + j).length) {
$('#representant_date_dem' + j).datetimepicker({ format: 'DD/MM/YYYY', date: moment() }); //not working
}
$('#hourDemandeurDebut' + j).datetimepicker({ format: 'HH:mm', date: moment() });
$('#hourDemandeurFin' + j).datetimepicker({ format: 'HH:mm', date: moment() });
}
};
</script>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
