You could do
$('[data-myAttr!=""]');
this selects all elements which have an attribute data-myAttr which is not equal to ” (so it must have been set); (only for elements that have their data attribute set in HTML not via jQuery)
you could also use filter() (which works for data attributes set from jQuery)
$('*').filter(function() {
return $(this).data('myAttr') !== undefined;
});