If you provide a function as the second argument attr, the function is executed once for each element in the selection, and the return value is set as the attribute value of that element.
The position in the selection is passed as the first argument to the callback; the current attribute value is passed as the second argument.
$("div").attr("id", function (arr) {
return "div-id" + arr;
})
, id div div-id . , div-id0, div-id1 ..
index, arr.