-1

I am new to JavaScript and would appreciate some guidance, I am trying to take a HTML value from page without Tax and update that same value to be inclusive of Tax.

Tax in my country is calculated at 15% of the value hence the 1.15

Javascript

var x = document.querySelector('.product-detail-exc-vat');
var y = 1.15;
var z = x * y;
x.querySelector('.product-detail-exc-vat').innerHTML=z;

HTML

<span class="product-detail-exc-vat">100</span>

My expected result is 115 within the HTML, where am I going wrong?

Lielow
  • 1

1 Answers1

0

var x = document.querySelector('.product-detail-exc-vat').innerText;
var y = 1.15;
var z = x * y;
document.querySelector('.result').innerHTML = z;
document.querySelector('.result2').innerHTML = z.toFixed(2);
value: <span class="product-detail-exc-vat">100</span><br />
value + tax: <span class="result"></span><br />
rounded value + tax (2 decimal places): <span class="result2"></span>
Flash Thunder
  • 11,672
  • 8
  • 47
  • 91