I am using the jQuery plugin Date Time Picker. Using the datetimepicker
, I am able to get the normal input working when the page loads, no problem. It is initialized using the following Javascript:
$('.datetimepicker').datetimepicker({
step:30
});
For fullness, the input works with the following html:
<input class="datetimepicker" type="text" name="datetime" />
So far so good. But, the issue is when loading AJAX (which works fine), the following input is loaded onto the page:
<input class="datetimepicker" type="text" name="datetime" id="popuppick"/>
Obviously I need to create an event handler to listen for the newly created input:
$(document).on("click", '#popuppick', function(){
alert("new link clicked!");
$('.datetimepicker').datetimepicker({
step:30
});
});
The alert works (only on the ajax loaded input), but it does not initialize the datetimepicker
plugin. In fact, the error message says that:
Uncaught TypeError: $(...).datetimepicker is not a function.
Which to me feels insane, because on the same page, before the AJAX is loaded, the first one works just fine!
I've tried throwing this into the success on AJAX callback, but the same thing happens (alerts and console.logs work but the datetimepicker
does not initialize). I've tried using the id as a selector but same result. Nothing is changing the fact that jQuery doesn't recognize this as a function, despite doing so on the first pageload.
I've tried using jsfiddle but I couldnt figure out how to load a plugin, so it wont really help me.