Thank you! Your code worked great and your explanation of the space and > is just what was needed.
Based on your explanation of >, because there was no > before the li, it was finding an li at any depth with an input child. By adding the > at the begging it is now only looking for direct children of #el. $("#el").find("> li > input"); On Sep 18, 6:01 am, "Richard D. Worth" <[EMAIL PROTECTED]> wrote: > Try > > $("#el > li > input") > > The (rough equiv) long-hand for that would be > > $("#el").children("li").children("input") > > So the space ( ) in css is analogous to .find(), and the > right-angled-bracket (>) to .children(). > > - Richard > > On Wed, Sep 17, 2008 at 11:56 PM, vtjiles <[EMAIL PROTECTED]> wrote: > > > I have the fairly simple markup below and am trying to only get only > > the checkboxes under the first level LI (Main 1 and Main 2), not the > > deeper ones. > > > <ul id="el"> > > <li> > > <input type="checkbox" value="1" /> - Main 1 > > <ul> > > <li> > > <input type="checkbox" value="1" /> - Sub 1 > > </li> > > <li> > > <input type="checkbox" value="1" /> - Sub 2 > > <ul> > > <li> > > <input type="checkbox" > > value="1" /> - Sub 2 Sub 1 > > </li> > > </ul> > > </li> > > </ul> > > </li> > > <li> > > <input type="checkbox" value="1" /> - Main 2 > > </li> > > </ul> > > > Using $("#el").find("li input") gets all 5 checkboxes. I've tried > > multiple variations of find("li input").not("li ul input") as well as > > using :not() in the selector which doesn't work. > > > One way that did finally work: > > var notgroup = $("#el").find("li ul input"); > > $("#el").find("li input").not(notgroup) > > > Why does it work if there is a variable which is the result of the > > selector, but not the selector itself? > > > Is there any better way to do this?