I'm not sure what you mean by "uppermost," but you can select the wrapper div closest to the span with $ ('span.bullet').parents('div.wrapper:first') or furthest out from the span with $('span.bullet').parents('div.wrapper:last')


--Karl
_________________
Karl Swedberg
www.englishrules.com
www.learningjquery.com



On May 22, 2008, at 4:54 PM, EdMartin wrote:


I have a setup like this

<div id="container">
<div class="wrapper">
 <div class="wrapper">
  <div><span class="bullet">Bullet</span>
   <!-- other stuff, potentially inner divs also containing bullets --

  </div>
 </div>
</div>
</div>

where there is an unknown number of wrapping "wrapper" divs. I want to
select the uppermost divs that contain a span.bullet, regardless of
the amount of wrapping. All such uppermost span.bullet-containg divs
will be wrapped to the same depth. But any or all of them may contain
other span.bullet-containing divs -- I don't want to select such non-
uppermost divs.

In practice, the depth of wrapping is probably only 0, 1, 2, or 3. So
I could deal with each of those separately, like this:

$( '#container' ).children().filter( ':has( span.bullet )' ) // no
wrapping
$
( '#container ' ).children ().filter( '.wrapper' ).children().filter( ':has( span.bullet )' ) //
1 layer of wrapping

and so on. But surely there has to be a more elegant way.

Any suggestions?

Reply via email to