Hi Luke -

I was able to get what you wanted, working using:
$("span:first-child").parent("div")

Right now, in jQuery, doing the XPath /../  is broken (since it's just
a cheap XPath -> CSS conversion). However, it's recommended that you
use methods like .parent() instead.

All that being said, normally you'd just be able to do:
    $("div:not([span:first-child])")

but that doesn't seem to be working correctly either. Ugh.

Sorry for the hassle :-/

--John

On 10/4/06, Luke Lutman <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> I'm having trouble removing a <div> from a set of matches if the div has a 
> particular
> first-child element.
>
> ##Here's what I've got:
>
> <div>123</div>
> <div><span>abc</span>xyz</div>
> <div><span>def</span>ghi</div>
>
> I have a $() object matching all divs (i.e. $('div')), but I only want to 
> process <divs> which
> don't have a span as their first child element. I should only end up 
> processing one div (the
> first one).
>
>
> ##Here's what I've tried:
>
> $('//span/../div')
> XPath with parent axis. Doesn't match anything.
>
> $('div').not('div/span/../div')
> jQuery object filtered with XPath with parent axis. Doesn't match anything
>
> $('div').not(('div > span').parent()[0])
> Only removes <div><span>abc</span>xyz</div>, leaving two matches.
>
> $('div').each(function(){
>         if($('span:first-child', this).size()) return;
>         alert(this);
> });
> This works, but it's kinda oogly.
>
>
> ##My question(s):
>
> Am I missing something with the XPath parent axis selectors? Shouldn't they 
> be matching something?
>
> Is there a better way to do this than the last method? I'd rather not iterate 
> over unnecessary
> elements.
>
>
> Thanks,
> Luke Lutman
>
> P.S. This is my first post to the list, so please be gentle ;-)
>
> _______________________________________________
> jQuery mailing list
> [email protected]
> http://jquery.com/discuss/
>


-- 
John Resig
http://ejohn.org/
[EMAIL PROTECTED]

_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/

Reply via email to