You can use each
to iterate over all elements with the class elem
$(".elem:first").data("hasdata","popup");
$(".elem").each(function(){
if ($(this).data("hasdata") === 'popup'){
$(this).css({background:'red'});
}
});
check this jsFiddle