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();
})
elementhave the correct CSS selector in it? Such as#idStartDate_3(with the#) to properly select the element? The other option might be that the click handler isn't binding to the new element properly on the DOM. You can inspect click attachments in Chrome's dev tools panel as well.Sourcestab at the top. Then, on the right, you'll seeEvent Listener Breakpoints. Expand that, expandMouse, and check the box next toclick. Then, go click something. If there's a click handler attached to it, the javascript will pause and you'll see the relevant handling code highlighted in theSourcestab.datepicker()to the end ofappend(). So it'd look like$("#ids tbody").append($clone).datepicker();elementto'idStartDate_'+count, but that id is never assigned to the element itself. Instead, you're giving the clone the id of"emlRow_" + count. What is the actualidof the cloned element, after it's cloned? Let's make sure you're correctly attaching to that.