-2

function increase( y) {
    var x = document.getElementById("result");
    var before= x.value;
    x.innerHTML= Number(before) + Number(y);
}
<b>Rp. <b id='result'>1240000</b> </b>
<button type="button" onclick="increase(80000)"> add </button>
jonatjano
  • 3,576
  • 1
  • 15
  • 20

1 Answers1

0

You have to use innerHTML to get the value of <b>.

function increase( y) {
  var x = document.getElementById("result");
  x.innerHTML= parseInt(x.innerHTML) + parseInt(y);
}
<b>Rp. <b id="result">1240000</b> </b>
<button type="button" onclick="increase(80000)"> add </button>
Sudhir Ojha
  • 3,247
  • 3
  • 14
  • 24