I am cloning a HTML table row and appending it to the end of the table. One of the fields is a start date. I want to add the jQuery UI datepicker to the cloned row but I am unable to make it work. After the .clone and before it's appended to the end of the table, the input and select elements id and name properties are incremented by 1. In the template row I am adding the datepicker to idStartDate and when it is cloned/appended the new id would be idStartDate_(row number). Shouldn't the $(element).datepicker() work? When I do an inspect element in chrome on the cloned row, it has the hadDatepicker class assigned but I still cannot get the picker to activate.
$("#addRow").click(function() {
count++;
$("#rowCount").val(count);
var $clone = $("#ids tbody tr:first").clone();
$clone.attr({
id: "emlRow_" + count,
name: "emlRow_" + count,
style: ""
});
$clone.find("input,select").each(function(){
$(this).attr({
id: $(this).attr("id")+"_" + count,
name: $(this).attr("name")+"_" + count
});
});
$("#ids tbody").append($clone);
var element = "idStartDate_"+count;
$(element).datepicker();
})