I am using jquery 1.10.2 and trying to clone a div, which I have done successfully, but I also need to change the id's of that div and all of its children, which I am currently unsuccessful at.
I have search this and found several examples to help e.g this and this, but they havent worked for. I really cant see why. I know I must be doing something really obvious wrong. What is the reason for what i have done not to work? (I have l left my attempts in - but commented)
$(document).ready(function () {
$("#btnSecondContact").click(function () {
$("#divCustomerData").removeClass("col-lg-6 col-md-6");
$("#divCustomerAddr").removeClass("col-lg-6 col-md-6");
$("#divCustomerData").addClass("col-lg-4 col-md-4");
$("#divCustomerAddr").addClass("col-lg-4 col-md-4");
$('#divCustomerData').after(
$('#divCustomerData').clone()
//$('#divCustomerData').clone().attr("id", "newId").find("#divCustomerData").attr("id", "#divCustomerData_cloned")
//$('#divCustomerData').clone(function () {
// $(this).attr("id", $(this).attr("id") + "_cloned")
//})
)
//$("#divCustomerData").clone(false).find("*[id]").andSelf().each(function () { $(this).attr("id", $(this).attr("id") + "_cloned"); });
$("#btnSecondContact").prop('disabled', true);
})
});