this is the code How to increase/ decrease value by 20?
<div class="slider">
<input type="range" min="1" max="100" value="0" class="img__slider" id="myRange">
</div>
<div>
<button id="prev">Prev</button>
<button id="next">Next</button>
</div>
js code
const prevbtn = document.querySelector('#prev');
const nextbtn = document.querySelector('#next');
const rangeValue = document.querySelector('#myRange');
nextbtn.addEventListener('click', () => {
let getValue = rangeValue.value;
getValue += 20
})
prevbtn.addEventListener('click', () => {
let getValue = rangeValue.value;
getValue -= 20
})
I tried increasing the value on click but it doesnt work
Use step attribute
<input type="range" min="1" max="100" value="0" step="20"class=" img__slider" id="myRange">
</div>
<div>
<button>Prev</button>
<button>Next</button>
</div>
You should setAttribute method:
const prevbtn = document.querySelector('#prev');
const nextbtn = document.querySelector('#next');
const rangeValue = document.querySelector('#myRange');
nextbtn.addEventListener('click', () => {
rangeValue.setAttribute('value', rangeValue.value + 20)
})
prevbtn.addEventListener('click', () => {
rangeValue.setAttribute('value', rangeValue.value - 20)
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.