Skip to content Skip to sidebar Skip to footer

How To Multiply Span Inner By Id Using Javascript?

I have a span which shows a currency. This is my span: It will only show the currency when it's being loaded through a browser and it needs th

Solution 1:

You can use innerHTML to get and set your span values.

document.getElementById('new').innerHTML = document.getElementById('v3_40').innerHTML * 12;
<spanid="v3_40">38.355</span>
* 12 = 
<spanid="new"></span>

EDIT:

After seeing the comments to this answer, here's a more detailed approach;

var originalPrice = document.getElementById('v3_40').innerHTML;
var price = originalPrice.replace(/\,/g,'');
var newPrice = parseFloat(price,20) * 12;
newPrice = newPrice.toLocaleString();

document.getElementById('new').textContent = newPrice;

Hope that helps!

Post a Comment for "How To Multiply Span Inner By Id Using Javascript?"