Jeśli wartość nie jest specyficzny, można spróbować this approach.
Demo poniżej wydruków "hej ludzie", w oparciu o $([attr1],[attr2],...,[attrN])
selektora:
<div class="container">
<div>no id</div>
<div id="a">hey</div>
<span name="b">you</span>
<p id="c">guys</p>
</div>
$('[id],[name]').each(function(){
console.log($(this).text());
});
podstawie tej konstrukcji, prosty wrapper może być napisane:
$.fn.hasAttrib = function() {
var attributes = [];
$.each(arguments, function(index, value){
attributes.push('[' + value + ']');
});
return $(this).find(attributes.join());
};
Wykorzystanie takiego pluginu w poniższym zestawieniu również drukuje "hej, wy, ludzie":
$('.container').hasAttrib('id','name').each(function(){
console.log($(this).text());
});
Co zaskakujące, brak udzielonych do tej pory odpowiedzi na Twoje interesujące pytanie. – gdoron