I have the following:
- item1
- sub1
- sub2
What about this approach? Clone the object, remove the clone's children and then find the text content.
$("#list li").click(function () {
alert($(this).clone().children().remove().end().text());
}
Perhaps not the most efficient approach, but it's entirely intuitive, pretty tidy, and you don't have to muck with your html.