0
<span id="rate">2388</span>

var = $("#rate")... 

I need get number value inside of element. any one know how to do it?

0

3 Answers 3

5
var number = +$("#rate").text();
//           |              \______get text of span as string
//           |_________________unary plus converts to numeric
Sign up to request clarification or add additional context in comments.

1 Comment

ha got it!, so + is the same as Number();
0

You can get the text inside your span using text() method and parseInt() to convert it to number:

var rateVal = parseInt($("#rate").text(), 10);

Comments

0

You can do also this

var result = Number($("#rate").html());

But becareful to use Number functon, Please have look this discussion for difference between parseInt and Number.

What is the difference between parseInt(string) and Number(string) in JavaScript?, as Roko indicated.

7 Comments

@RokoC.Buljan now edited the answer with parseInt.
you should remove your answer, cause otherwise it's a duplicate of Felix's answer, and BTW you're missing the radix parameter.
Fexlix is using text(), and I used html(), does this consider as duplicate answer?
Almost, .html() is even the worse scenario, but now that you're using parseInt() makes no difference between your and Felix's. + You're still missing the parseInt radix parameter.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.