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

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

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

416E64726577
  • 2,214
  • 2
  • 23
  • 47
Ben
  • 2,562
  • 8
  • 37
  • 62

3 Answers3

5
var number = +$("#rate").text();
//           |              \______get text of span as string
//           |_________________unary plus converts to numeric
nnnnnn
  • 147,572
  • 30
  • 200
  • 241
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);
Felix
  • 37,892
  • 8
  • 43
  • 55
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.

Community
  • 1
  • 1
Suman Bogati
  • 6,289
  • 1
  • 23
  • 34