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/

Reply via email to