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 Swedberg
www.englishrules.com
www.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