. , each. , , id, "table_", ( "list_" "id_" ). , , , , . , ().
, , .
each id DOM this.id.
, , .
:
jQuery , span id "id_", :
$("#list").find('span[id^="id_"]').each(function(index) {
this.id = "id_" + (index + 1);
});
find, , each, . , 1, 0, index, jQuery each. Assigning the IDs can be done with the raw DOM element ( in the ), .
find, :
$('#list span[id^="id_"]').each(function(index) {
this.id = "id_" + (index + 1);
});
. , , :
$('#list div[id^="list_"]').each(function(listIndex) {
++listIndex;
this.id = "list_" + listIndex;
$(this).find('table[id^="table_"]').each(function(tblIndex) {
++tblIndex;
this.id = "table_" + listIndex + "_" + tblIndex;
$(this).find('span[id^="id_"]').each(function(spanIndex) {
++spanIndex;
this.id = "id_" + listIndex + "_" + tblIndex + "_" + spanIndex;
});
});
});