I have a weird problem where I can’t use the normal sizzle selector to correctly select something in jQuery:
These two lines don’t do the same thing.
ele.children("div.a > div").addClass("badActive");
ele.children("div.b").children("div").addClass("active");
ele.children("div.a > div")selectsdivs that are both children ofdiv.aelements (from the>combinator) andele(from the.children()call). It also implies thateleitself represents adiv.aelement.ele.children("div.b").children("div")selectsdivs that are children ofdiv.belements, that themselves are children ofele.eleitself may be any kind of element, but it must containdiv.bchildren, and itsdiv.bchildren need to havedivchildren.As Felix Kling says in the above comment, you need to use
.find()to search all descendants. This applies to your first case with the>combinator, asele.find("div.a > div").