Are there multiple spans inside #count?
If so, you could try
$("#counts span:first").text()
Are there multiple spans inside #count?
If so, you could try
$("#counts span:first").text()
The selector '#counts span'
will pick up any <span>
tags that are a child of #counts (or a children of its children, etc.), so my guess is that you're accidentally selecting more nodes than you meant to grab.
It's hard to say how to modify your XPATH query correctly without seeing the page's source, though.
Try to use it as a number:
var valueAsInt = parseInt($('#counts span').text());
If that works you can add convert it to a string by adding an empty string at the end of the expressions.
If that doesn't work you have a number of ways to debug this. Try:
alert($('#counts span').text());
If that returns 10, the problem is in the parsing. If that returns 10000 then the element contains a different value than you think so you can try:
alert($('#counts span').parent().html());
and verify the HTML does indeed contain 10
inside the <span>
.
You can use $('#counts span').html(); and it will only return the innerHtml from the first match. The simplest solution would be to add a id to the span to make sure you get just what you want. $('#span-id').text(); or $('#span-id').html(); They should both return the same value at this point.