You do not need to assign identifiers to divs to customize them. Say the following variable shows - 'index of target div = index of element in array', 'ID of existing ID to append'
var ids = ['divid1','divid2','divid3'];
You can then use the following code to add a div with the identifiers above to the corresponding target DIVs:
$('.detail-group').append(function(i) { return $('#' + ids[i]);
Alternatively, suppose you can select existing DIVs through a common class, say .content-div and divs represents these divs , then you can do it like this:
var divs = $('.content-div'); $('.detail-group').append(function(i) { return divs[i]; });
However, if you add the same div to all three target DIVs, consider removing the identifier before you get duplicate identifiers:
//select the one DIV var oneDiv = $('#oneDiv'); //detach it from DOM oneDiv.detach(); //remove ID oneDiv.removeAttr('id'); //clone oneDiv and add to the target DIVs $('.detail-group').append(function() { return oneDiv.clone(); });
source share