I have created HTML INPUT element with type="RANGE" and with id="slider". Why cannot I access its value using getAttribute("value") method? Debugger shows that there is an attribute named "value" with some value which is not equal to the value of the element. Should not the value of range element be its attribute?
var sliderValue1=document.getElementById("slider").getAttribute("value");
var sliderValue2= document.getElementById("slider").value;
you can't do that because,
.getAttribute("value")
return the value of the element write into the html (if you don't change that, the default value).Example:
with:
<input type="range" id="slider" value="500">
document.getElementById("slider").getAttribute("value");
return500
also if you use input to change range.It's true, and right. If you set a default value it never change (is useful to reset the input).
No, the current value of the element is stored outside the html, so to access to the current vale you must use:
document.getElementById("slider").value;
, but it's the same with all type of input not only on range.