I may have misunderstood, but I think you're trying to do the following:-
// loop over all divs which have an id
$('div[id]').each(function() {
// create a selector matching the div id with the data-attribute
var $divData = $('div[data-attribute="' + this.id + '"]');
// if it exists, set the text
if ($divData.length) {
$divData.text( $(this).text() );
}
});