MatthewMueller/cheerio — Issue #1: Issue with selecting nested elements
Author: LrdGrmRpr
Created: 2011-11-04 06:13:04+00:00
State: open

I was attempting to select elements based DOM structure, e.g. "li.a div.b span.c" (because span.c exists in other structures as well, but I only want to access those that match this structure), but instead of the 40 elements that match on the page, the code returned 840 elements, with multiple duplicates, so I assume it gets all the possible combinations and just returns them all.

E.g.

$('li.a div.b span.c').each(function(i, el) {
// Has 840 items
});

vs.

$('span.c').each(function(i, el) {
if($(this).parent('div').attr('class') == 'b' && $(this).parent('div').parent('li).attr('class') == 'a') {
// Has 40 items
}
});

Is this a (typical) user error or an issue with the selector?