$('[price]').each(function(){ var id = this.id; data[id] = {}; data[id].name = $(this).attr('name'); // ... });