-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>

2
  • A <b> element doesn't have a .value. Use innerText. Commented Jul 30, 2020 at 10:14
  • it works jsfiddle.net/b0kd26oa Commented Jul 30, 2020 at 10:15

1 Answer 1

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>

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.