var attachArr = []; $('#attachDiv').find('p').each(function(){ attachArr.push($(this).attr('id')); }); .XXXX XXXX