-1

I need to get numbers only (strip commas and currency symbol) from a value in an id called "price". I have the following:

function() {
var element = document.querySelector('*[id^="price"]');
var price = element.innerHTML.match(/\d*\.\d*/)[0];
return price;
}

This works fine of the value is something like "£10.50". But if my value has a comma such as "£2,050.00" it returns "050.00".

How do i get just numbers and replace any currency symbols and commas?

chappers
  • 466
  • 1
  • 6
  • 17
  • 1
    Possible duplicate of [JavaScript get number from string](https://stackoverflow.com/questions/10003683/javascript-get-number-from-string) – shaair Apr 24 '18 at 07:26

1 Answers1

0

Got it:

function() {

var element = document.querySelector('*[id^="bew-price"]');
var price = element.innerHTML.replace(/\u00A3/g, '');
var trueprice = price.replace(/,/g , "");


return trueprice;

}
chappers
  • 466
  • 1
  • 6
  • 17