Yeah holy cow, I meant " ", not ">". It's a strange edge case, I'm
sure even wanting to do such a thing most of the time might indicate
poor design. I'm injecting UI into arbitrary pages and want to style
it without damaging the host page. Because of the way my style
extension works, dynamic rules are applied in the context of each
newly created element, essentially calling .is() on the element
and .find() if .is() doesn't match, applying rules. Setting up my
rules in the form "#div-which-contains-all-my-stuff h1" is what
tripped me up; until the possible 1.3 .is() upgrade, classes will have
to do. Thanks!

On Oct 22, 6:28 pm, ricardobeat <[EMAIL PROTECTED]> wrote:
> Following your logic, an L4 element will never be a direct child of an
> L1, so that would always return 0. Also you don't need two objects to
> do what you were trying at first, you can do $('some > thing',
> '#inhere')
>
> Let me see if I understand you. Given the following mark-up:
>
> <body>
>
> <div class="L1">
>   <p>
>       <span class="L3">
>            <a class="L4" />
>       </span>
>   </p>
> </div>
>
> <div class="L1 thisOne">
>   <p>
>       <span class="L3 other">
>            <a class="L4" />
>       </span>
>   </p>
> </div>
>
> </body>
>
> You want to find only the <a> (4) elements that are children of <div>
> (1) AND children of <span>(3). Right. L4 is not a direct children of
> L1 so you need another approach.
>
> $('span.other a').filter(function(){ return !!$
> (this).parents('div').length })
> which equates to
> $('L3.other L4').filter(function(){ return !!$
> (this).parents('L1').length })
>
> or, if what you want is the opposite, to find <a>'s in <span> that are
> also a child of <div>
>
> $('span a').filter(function(){ return !!$
> (this).parents('div.thisOne').length })
> which equates to
> $('L3 > L4').filter(function(){ return !!$
> (this).parents('L1').length }) // returns true if the element is a
> child of L1
>
> There are many ways of simplifying that based on your element classes
> or attributes, but that's all I could come up with without seeing your
> HTML.
>
> cheers,
> - ricardo
>
> On Oct 22, 6:16 pm, Dan Finch <[EMAIL PROTECTED]> wrote:
>
>
>
> > You're right, I do that all the time :). I'm getting my side effects
> > mixed up. What I can't actually do is match against ancestors of the
> > context. For example, $( ".L1>.L4", $( ".L3" ) ), where the n
> > represents the level of DOM depth.
>
> > On Oct 22, 2:38 pm, MorningZ <[EMAIL PROTECTED]> wrote:
>
> > > Have you tried those?
>
> > > There's no reason why
>
> > > $( "p>a", $( "div" ) );
>
> > > wouldn't find all <a> that are direct descendants of <p> tags inside
> > > <div> tags
>
> > > On Oct 22, 2:43 pm, Dan Finch <[EMAIL PROTECTED]> wrote:
>
> > > > If there's a way, what would it take to be able to use complex
> > > > selectors (those with " ", "~", ">", etc.) with filtering functions.
> > > > For example,
>
> > > > $( "div" ).find( "p>a" );
> > > > $( "p>a", $( "div" ) );
>
> > > > Thanks- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -

Reply via email to