Suppose the following DOM structure:
.grandparent
.parent
.child .successful
.a
.b
.an-arbitrary-subtree
.parent
.child
.a
.b
.a-different-arbitrary-subtree
.adopted
.child
.a
.b
.another-arbitrary-subtree
.with-different-parents
.but-sometimes-common-css-classes .successful
Were I to $('.grandparent').find('.successful')
unsurprisingly, I'd get back [.child .successful, .but-sometimes-common-css-classes .successful]
Is there any way I might prevent jQuery's find method from traversing below the .child nodes? Perhaps I could reimplement $.find() myself and add a top-level class on the node to halt the search (in this case on .b
)
Why am I asking? Even though we do not yet have Shadow Dom, I'd like to create components that can contain components (created by other developers anonymously) without worrying about leakages. Polymer isn't stable enough, yet. I prefer to scope my jQuery selectors in these components, but can only scope from the top node of a subtree, and have no means yet to constrain scope into the depths of the tree.