I sketched up a plugin for this.

It's at http://ff6600.org/j/jquery.dig.js

Live example at http://jsbin.com/ugena/

It just steps throught the children with the tag given and executes a
function for each one, passing it it's 'hierarchy level' in relation
to the container where the plug-in was called. Any new children added
in the process will be taken into account on the next step.

hope it helps!

- ricardo

On Nov 26, 3:52 pm, Mark Gibson <[EMAIL PROTECTED]> wrote:
> I don't think I stated my problem fully.
>
> What I'm trying to do it process the elements recursively, so using
> the <ul>'s as an example:
>
> 1. Find the shallowest <ul>'s (Karl's solutions would work here).
> 2. For each <ul> found:
> 3. Add content to the <ul>.
> 4. Find the next shallowest <ul> within each <ul>.
> 5. Recurse from step 2 (until there are no more deeper <ul>'s).
>
> var dostuff = function(elem) {
>   $(elem).findShallowest('ul').each(function() {
>     // do stuff, add content
>     dostuff(this);
>   });
>
> }
>
> It's important that the elements are processed in this manner,
> as content is added which may include more <ul>'s which in turn
> need processing.
> Also the exact structure is not known, so I can't rely on child '>'
> ops.
>
> I think it could be done by stopping find() from going any deeper
> once it finds match, but from looking at the jQuery src, find() is a
> little baffling.
>
> Thanks for help so far
> - Mark.
>
> On Nov 17, 7:28 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
>
> > Hi Mark,
>
> > I took a look at your original post again, and from your description  
> > there it looks like this would work:
>
> > $('ul').filter(function() {
> >    return !$(this).parents('ul').length;
>
> > })
>
> > --Karl
>
> > ____________
> > Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> > On Nov 17, 2008, at 10:58 AM, Mark Gibson wrote:
>
> > > The trouble is that the elements i'm looking for are not necessarily
> > > direct children of the container,
> > > so > isn't going to work. What I really need is to stop jQuery from
> > > searching any deeper once it
> > > finds the first <ul>, but continue the search at the same and
> > > shallower levels.
> > > Is  there a way to do this with a $.expr[':'] plugin?
>
> > > On Nov 11, 11:24 am, Klaus Hartl <[EMAIL PROTECTED]> wrote:
> > >> That won't work. :first-child will give you *all* uls that are the
> > >> first child of any element:
>
> > >> <div id="container">
> > >>     <ul><!-- is first child -->
> > >>         <li>
> > >>             <ul> ... </ul><!-- is first child -->
> > >>         </li>
> > >>     </ul>
> > >> </div>
>
> > >> If you need the topmost ul use the ">" combinator:
>
> > >> $('#container > u')
>
> > >> Oh, jQuery has some documentation about 
> > >> selectors:http://docs.jquery.com/Selectors
>
> > >> En plus knowing the spec doesn't hurt 
> > >> either:http://www.w3.org/TR/CSS21/selector.htmlhttp://www.w3.org/TR/css3-sel...
>
> > >> --Klaus
>
> > >> On 11 Nov., 02:07, "Hector Virgen" <[EMAIL PROTECTED]> wrote:
>
> > >>> Oops, it's actually $('#container ul:first-child')
> > >>> Here's a nifty page of CSS3 
> > >>> selectors:http://www.w3.org/TR/2001/CR-css3-selectors-20011113/#selectors
>
> > >>> -Hector
>
> > >>> On Mon, Nov 10, 2008 at 5:06 PM, Hector Virgen  
> > >>> <[EMAIL PROTECTED]> wrote:
> > >>>> $('#container ul:first') should give you the first UL in the  
> > >>>> container
> > >>>> -Hector
>
> > >>>> On Mon, Nov 10, 2008 at 4:50 PM, Mark Gibson  
> > >>>> <[EMAIL PROTECTED]> wrote:
>
> > >>>>> Anyone know how I can find the topmost elements of a certain  
> > >>>>> type, eg.
>
> > >>>>> Say I have several <ul> lists on a page, which in turn contain  
> > >>>>> sub-
> > >>>>> lists, and so on.
> > >>>>> Is there a selector I can use to find all the topmost <ul>  
> > >>>>> elements.
>
> > >>>>> I've been raking my brains over this, and can't see a way with css
> > >>>>> style selectors,
> > >>>>> have i overlooked something?
>
> > >>>>> Ideally I'd like to do:
> > >>>>> $('ul:topmost')
>
> > >>>>> or:
> > >>>>> $('#container ul:topmost')
>
> > >>>>> Cheers
> > >>>>> - Mark

Reply via email to