Reputation: 4811
Please find the below code for more information.
$('body').on('click', '.deleteRow', function () {
});
This way it will work for all the dynamically created elements of class 'deleteRow'. But when it comes to Datepicker initialization How can i do the same? I am creating some dynamic text boxes with class 'datepicker' and i want to initialize datpicker for all of them
$('.datepicker').datepicker(); this will work for already existing elements only not for the dynamically created items
Upvotes: 1
Views: 60
Reputation: 74738
This line you have to put after appending of new row:
$(id/class).append(row); // just an example
$('.datepicker').datepicker(); //<----initialize it here when elem is in DOM
You have to initialize it when you create new elements.
Or you can initialize it explicitly with focus
event:
$('body').on('focus', '.datepicker', function () {
$(this).datepicker(); // this will intialize for current focused .datepicker
});
Upvotes: 1