0

document.getElementById("volslider").value -= -step; //WORKS as intended
document.getElementById("volslider").value += step; //Takes slider to 50/100 for any step value
<input type="range" id="volslider" min="0" max="100" value="100" oninput="updateVolume(this.value)"/>

The above code produces different results although it shouldn't. Does anyone know why?

Windfish
  • 68
  • 7
  • 1
    `value` is always a **string**. `+` is defined for both strings and numbers, but `-` isn't, so `-` does implicit conversion to number where `+` does not. – T.J. Crowder Jul 10 '21 at 11:58
  • 1
    Note that you can use `valueAsNumber` on modern browsers, see [`HTMLInputElement`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement). – T.J. Crowder Jul 10 '21 at 12:01

0 Answers0