$(function() { var author = $('.review-list .author'), len = author.length; author.attr('id', function(i,_) { return 'id-' + (len - i); }); });