The following tests determine if the first character is a dollar sign, and if so, takes the rest of the string:
var csqft_price = $('#testspan').html(); var price = +(csqft_price.charAt(0)==="$" ? csqft_price.substr(1) : csqft_price);
Of course, if you know that there will always be a dollar sign, you can simply do this:
var price = +csqft_price.substr(1);
Note. I usually prefer the unary plus operator to convert a string to a number, so I used this in my answer above - you can change +(...) to parseFloat(...) if you want.
source share