How can i get the value Communications?

<li class="current">
    <a href ="" class="sf-with-ul">
        Communications<span class="sf-sub-indicator"></span>
  • This question is not related to SharePoint specifically and would be better asked on a JQuery forum. – Charles Lee Sep 13 '10 at 8:25
  • @Patrick: You have been repeatedly warned about asking off topic questions. If there's something you're not clear about regarding this please e-mail team@sharepointoverflow.com. Your account has been suspended for 48 hours. – Alex Angas Sep 14 '10 at 1:38

Previous answers are correct, but I'll add to it a tad.

If you want a solution that works consistently and you only want that one item (as opposed to a parent object containing all of the matches), you really need to tie it to an ID.

For an example, if this was a nav menu it probably has an id attribute (somewhere above it). It doesn't matter if that id is called on the ul tag, or on some higher object like a div or table. You can then grab instances of sf-sub-indicator within that ID to ensure it's processed consistently. Using a blanket selector like you are means if someone adds a anchor tag with that class it'll get returned back since there's no scope on it.

The better approach is to use something like $("#divid li.sf-sub-indicator").text();

  • Thanks for the solution and i get what you mean. i'm using a UL and it has no id.But will work something out – Patrick Sep 14 '10 at 4:43

see http://api.jquery.com/class-selector/


From your excerpt, there is no way to guarantee that an expression will return the value "Communications". It depends on the rest of your page.

Based only on your 4 lines, you can do this:

$("a .sf-with-ul").text()

Not the answer you're looking for? Browse other questions tagged or ask your own question.