Can you just make life REALLY easy on yourself and put the text in a
<span> tag or something?
ie/
<ul>
<li><span>List Item1</span></li>
<li><span>List Item2</span>
<ul>
<li>Sub Item1</li>
<li>Sub Item2</li>
</ul>
</li>
</ul>
then
http://docs.jquery.com/Selectors/firstChild
would make it a snap to get the text()
On Feb 5, 3:00 pm, "[email protected]" <[email protected]> wrote:
> Hi,
> I'm trying to traverse a list that has some sub-lists nested, i.e.
> <ul>
> <li>List Item1</li>
> <li>List Item2
> <ul>
> <li>Sub Item1</li>
> <li>Sub Item2</li>
> </ul>
> </li>
> </ul>
>
> I'm trying to grab the text of List Item2, but without the text of the
> sublist items. Right now if I use:
> $('ul li').text() -- it returns the text of the List Item and the
> text of any sub items.
>
> I'm thinking I may have to write a regular expression to filter out
> the sublist, but was wondering if jQuery could handle this? Any ideas
> appreciated.
>
> AM