(Jquery) Change font size after decimal point for (javascript dynamically generated) numbers

Viewed 28

I was looking for a way to change the digits after the decimal point. I have found this useful answer. The code there is:

$.each($('.price'), function(){
var price = $(this).html();
$(this).html(price.replace(/(\D*)(\d*\.)(\d*)/,'<span style="font-size:16px;">$1</span><span style="font-size:22px;">$2</span><span style="font-size:14px;">$3</span>'));
});

Unfortunately, my numbers are also generated by javascript. So they basically do not exist in the page code. In other words, in the browser's console I can see the

<span class="price">$ 270.30</span>

if I right click on the price and then inspect, but not when I use Ctrl+U and search for it.

The error displayed in the console is

Uncaught TypeError: Cannot read properties of undefined (reading 'each')

Is there a way to make this code work for dynamically generated prices? Or maybe other solution to change the size of the digits?

Thank you.

0 Answers
Related