javascript - How to clone element when i use $.append -
i have data json when page load pull combo box.
function dataprovide(){ //load data json selectvalues = { "pilih" : "-pilih-", "id" : "id", "emp_name" : "employee name", "photo_path" : "photo path", "emp_id" : "employee id", "birth_place" : "birth place", "birth_date" : "birth date" }; $.each(selectvalues, function(key, value) { $('#data1_1') .append($("<option></option>") .attr("value",key) .text(value)); }); } $(document).ready(function() { dataprovide(); });
when page load, generated data input combo box, problem when want perform additional row in table using $.append....
$(".addcf").click(function(){ count += 1; $("#customfields").append( '<tr>' + '<td>' + '<select id="data1_'+count+'" class="tabelbaru" name="data1[]">' + '<option value="pilih" selected >pilih</option>' + ... clone element $('#data1_1') + ... clone element $('#data1_1') + ... clone element $('#data1_1') + '</select>' + '</td>' + '<td>' + '<input id="data2_'+count+'" type="text" name="data2[]" class="data2" value="" placeholder=""/>' + '</td>' + '<td>' + '<input id="data3_'+count+'" type="email" name="data3[]" class="data3" value="" placeholder=""/>' + '</td>' + '<td>' + '<a href="javascript:void(0);" class="remcf">remove</a>' + '</td>' + '</tr>' ); });
how use function $.clone take $('#data1_1')
element along data created when first page opened??
try
$(".addcf").click(function () { count += 1; var $row = $('<tr>' + '<td>' + '</td>' + '<td>' + '<input id="data2_' + count + '" type="text" name="data2[]" class="data2" value="" placeholder=""/>' + '</td>' + '<td>' + '<input id="data3_' + count + '" type="email" name="data3[]" class="data3" value="" placeholder=""/>' + '</td>' + '<td>' + '<a href="javascript:void(0);" class="remcf">remove</a>' + '</td>' + '</tr>').appendto("#customfields"); $row.find('td:first').append($('#data1_1').clone()) });
Comments
Post a Comment