1

I am trying to generate datepicker for jquery generated html input as below :

<input type="text" class="cal" />
<a href="#" id="datepicker">Show </a>
<div id="newdp"></div>

And the JS

var datePickerOptions = {
    dateFormat: 'yy-mm-dd',
    firstDay: 1,
    changeMonth: true,
    changeYear: true,
}
$(document).ready(function () {
    $(".cal").datepicker(datePickerOptions);
 });
$('#datepicker').click(function(){
   var html = '';
    html += '<input type="text" class="cal" />';
    $('#newdp').html(html);
});

I use the js codes as explained in jquery datepicker not working on dynamically created html. But in my case its not working !

JSFiddle

1

1 Answer 1

2

You need to attach the datepicker to the newly created html element

$('#datepicker').click(function(){
   html += '<input type="text" class="cal" />';
   $('#newdp').html(html);
   html.datepicker(); // apply the date picker
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.