In my JS code below, when I try to do .value on userInput I cannot do so, I " /> In my JS code below, when I try to do .value on userInput I cannot do so, I " /> In my JS code below, when I try to do .value on userInput I cannot do so, I "/>

Javascript: Can only get nodeValue() not value() from an input?

533 Views Asked by At

I have the following HTML Input:

<input type="number" id="input-number"/>

In my JS code below, when I try to do .value on userInput I cannot do so, I can only do .nodeValue.

Why is this?

// elements on page
const userInput = document.getElementById('input-number');
const addBtn = document.getElementById('btn-add');
const subtractBtn = document.getElementById('btn-subtract');
1

There are 1 best solutions below

0
Sifat Haque On BEST ANSWER

I just found it's working fine here. You can check this example.

const userInput = document.getElementById('input-number');
const addBtn = document.getElementById('btn-add');
const subtractBtn = document.getElementById('btn-subtract');

addBtn.addEventListener('click', (e) => {
  userInput.value++;
})

subtractBtn.addEventListener('click', (e) => {
  userInput.value--;
})
<input type="number" value=0 id="input-number"/>
<button id="btn-add">+</button>
<button id="btn-subtract">-</button>