Thanks for the quick responses guys.
Klaus, I'm afraid your approach didn't seem to work, but Karl yours
worked perfectly, and looks a bit more elegant than Klaus' as well ;o)
I'd not seen the filter function though so I've learnt something from
both posts, thanks again guys.
Chris
On Sep 13, 10:38 pm, Karl Swedberg <[EMAIL PROTECTED]> wrote:
> Hi Chris,
>
> Try this:
>
> $("ul:has(> li:only-child)").addClass("solo");
>
> That will select only the ul that has a child li (not a nested one)
> that is an only child.
>
> --Karl
> _________________
> Karl Swedbergwww.englishrules.comwww.learningjquery.com
>
> On Sep 13, 2007, at 4:23 PM, smuggyuk wrote:
>
>
>
> > Given a ul hierarchy as below, I'm struggling to write a JQuery
> > selector that will give me a ul that contains only one li element,
> > that I can then add a class to, in this example the ul is the one that
> > contains the li "Only Child".
>
> > <ul>
> > <li><div><a href="#">First</a></div>
> > <ul>
> > <li><div><a href="#">Only Child</a></div></li>
> > </ul>
> > </li>
> > <li><div><a href="#">Second</a></div></li>
> > </ul>
>
> > So far I've tried permuations on a theme of:
> > $("ul:has(li:only-child)").addClass("solo");
> > and
> > $("ul li:only-child").addClass("solo"); - this one gets close, but
> > adds the class to the li rather than the ul.
>
> > I'm sure this is possible, so any help gratefully received,
> > Chris