> $('div').each(function(){ > var id= $(this).attr('id'); > $('span').each(function(){ > if(id = $(this).attr('class')){ > alert($(this).text()); > } > }); > });
That attr('class') bit will get you in to trouble. I suggest using .is(), and in fact, if you know the class you're looking for, you don't need the second each loop: $('div').each(function(){ $('span.' + this.id).doSomethingWithIt(); }); The OP seems a little vague about what the desired result is... --Erik