Hello, dear experts! Help, please, in solving, I am sure a very simple question for you.
There is a text box in which to the left is an add icon. When clicked, the next text field is added below with the delete icon, etc. To do this, use the first js with this code.
$(document).ready(function(){ var maxField = 10; //Input fields increment limitation var addButton = $('.add_button'); //Add button selector var wrapper = $('.field_wrapper'); //Input field wrapper var fieldHTML = '<input type="text" name="" class="data_picker" value="" />'; //New input field html var x = 1; //Initial field counter is 1 $(addButton).click(function(){ //Once add button is clicked if(x < maxField){ //Check maximum number of input fields x++; //Increment field counter $(wrapper).append(fieldHTML); // Add field html } }); $(wrapper).on('click', '.remove_button', function(e){ //Once remove button is clicked e.preventDefault(); $(this).parent('div').remove(); //Remove field html x--; //Decrement field counter }); });
Inside the var fieldHTML input with the data_picker class. This is the class that js uses to enter time. Here is the code.
$(function(){ $('.data_picker').timepicker().each(function(i){ eval($(this).text()); }); });
The question is that if you just use the .time_picker class in plain html, everything works fine. But when I put it in js, which adds fields, it doesn't work. Please tell me how to make the second js work when adding fields. I really need your help. Thank you very much in advance.