Как отследить значение input range при перемещение ползунка без jquery?
Есть input range
<input type="range" id="similarity" class="range" min="-1.0" max="1.0" value="0" step="0.1"></input>
нужно отслеживать его значение при перемещение ползунка
document.getElementById("similarity").onclick = function(){
console.log(document.getElementById("similarity").value)
Возможно ли это сделать?
Ответы (1 шт):
Автор решения: HaZcker
→ Ссылка
const someInput = document.getElementById('someId')
const output1 = document.getElementById('output_1')
const output2 = document.getElementById('output_2')
someInput.addEventListener("input", onInputHandler);
someInput.addEventListener("change", onChangeHandler);
function onInputHandler(e) {
output_1.innerText = `input: ${e.target.value}`
}
function onChangeHandler(e) {
output_2.innerText = `change: ${e.target.value}`
}
<input type="range" id="someId" />
<h2 id="output_1"></h2>
<h2 id="output_2"></h2>