Is it possible to have a string, like $10.50 and do math on it within javascript? I can’t find an answer on this site.
HTML:
<p id="cost">$10.50</p>
---
<div id="output"></div>
JavaScript:
$('#output').html($('#cost').html() / 2);
Output:
NaN
You can do math on it if you strip away the dollar sign using; since it’s usually at the first position, you can simply use
.substring(1)on the string value.