I am trying to make all original and appended elements as a date picker but only the original works
I tried this code but next line of inputs appears just as a normal input not a jquery datepicker hope you can find a solution thanks.
Here is my code.
<html>
<head>
<title></title>
</head>
<script type="text/javascript">
$(document).ready(function(){
$(".inputdate").datepicker({
});
$(".samplebtn").click(function(){
$(".samplediv").append("<input class='inputdate' type='text' name='date'>");
});
});
</script>
<body>
<div class="samplediv">
<input class="inputdate" type="text" name="date">
</div>
<button class="samplebtn">Add</button>
</body>
</html>
After bind dynamic item re initialize date picker.
$(".samplebtn").click(function() {
$(".samplediv").append("<input class='inputdate' type='text' name='date'>");
$('.samplediv').find(".inputdate").datepicker({
});
});
You should attach .datepicker() to those new elements.
Try this for your .append() script:
$(".samplediv")
.append("<input class='inputdate' type='text' name='date'>")
.promise()
.done(function() {
$(this).find('.inputdate').datepicker({ ... });
});
Hope this help. :D