i am noticing a bug in jquery find.
if i call foo.find with a selector that might reference foo itself, it won’t work. example here.
http://jsfiddle.net/CgfPj/6/ (EDIT: UPDATED THE fiddle to more clearly explain what i’m trying to do)
test.find should be able to find a span that is a child of a div, but it can’t seem to since the div is test itself. is this a bug?
#testis thedivyou’re referencing..find()returns the descendants of#testmatching your given selector.#testhas no descendantdivs, hencetest.find("div > span")doesn’t match any elements.To get the direct
spandescendants of#testyou should use:Fiddle
Edit as per OP edit:
Will get all
spans direct descendant of#testas well as allspanelements direct descendant ofdivs inside of#test– fiddle.There’s no such thing as a
:parentIs(div)selector in the CSS selectors spec nor in jQuery as far as I’m aware of, but you can easily fill that gap by using a filter function:Fiddle