Hey Chris,

If the latter example you gave adds the class to li, you could simple
do:

$("ul li:only-child").parent().addClass("solo");

However, looking at your first example and the API for only-child
and :has, it looks to me like the syntax for the first statement
should work...

Jacob

On Sep 13, 2:23 pm, smuggyuk <[EMAIL PROTECTED]> 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

Reply via email to