Something like this would do the trick ( The Fiddle ):
function GetWithSameAttributes (parID) { var output = new Array(); $('#'+parID).children().each(function () { if ($(this).is('[attr1="'+$(this).attr('attr2')+'"]')) output.push($(this).html()); }); return output; } $(function () { for (val in GetWithSameAttributes('Items')) document.writeln(val + ' has the same attributes<BR/>'); });
with html something like:
<div id="Items"> <div attr1="foo" attr2="bar">A</div> <div attr1="bar" attr2="bar">B</div> <div attr1="foo" attr2="bar">C</div> <div attr1="foo" attr2="foo">D</div> </div>
source share