1

I am trying to only pull out the number "88" in the example below:

    <li>
       <a href="website">5 stars</a>
       (88)
    </li>

I have tried:

var theLi= $('li');
var theNumber = $(theLi.get(0).nextSibling).text();

but nothing comes up..it is blank.

ToddN
  • 2,901
  • 14
  • 56
  • 96

4 Answers4

0

how about

var theNumber = $('li').after( $('a') ).text().replace('(','').replace(')','')

This works.

Control Freak
  • 12,965
  • 30
  • 94
  • 145
0

This same thing has been answered in another thread: Using .text() to retrieve only text not nested in child tags

You clone the li, remove the child elements, and extract the text.

Community
  • 1
  • 1
nopuck4you
  • 1,730
  • 14
  • 20
0

This should work, http://jsfiddle.net/elclanrs/bPqDR/:

$('li').clone().children().remove().end().text();
elclanrs
  • 92,861
  • 21
  • 134
  • 171
0

You could use lastChild for the given structure.

li.lastChild.nodeValue

See an example.

Anurag
  • 140,337
  • 36
  • 221
  • 257