I am using jinja to spit out integers into my HTML. I want to convert the integer to USD using JavaScript. My product.cost variable gives the integer 100 and my inttousd() function runs, but does not edit the text inside my HTML. Is there a way to get javascript to update inline or do I have to assign a class to each element and update it that way?
Here is myjinja template:
<script>inttousd("{{ product.cost }}")</script>
Here is a javascript function I made to convert the integer to USD. The console.log shows the function running, but inspect shows everything exactly how jinja saw it except product.cost is given as the integer 100.
function inttousd(str) {
//Add commas for thousands on first slice
const [dollars, pennies] = [str.slice(0, -2), str.slice(-2)];
console.log("$"+dollars+"."+pennies)
return "$"+dollars+"."+pennies;
}