Hi. I need to get the value inside a
<td> through its selector.
<td> contains the total value of a purchase (within a checkout).
Using the console:
in this case I can get the element:
<td class="monetary" data-bind="text: totalLabel">R$ 75,22</td>
however I need to get the value 75.22 alone.
How should I proceed?
Generally speaking to capture content in a string you can use regular expressions . In this case:
'R$ 75,22'.match(/\d+,\d+/) would be
In regular expressions
\d means digit,
+ means 1 or more of the previous selector.
To apply in your case, you can do this:
var td = document.querySelector(".monetary"); var preco = td.innerHTML.match(/\d+,\d+/);