Reputation: 1325
<input type="range" value="0" min="0" max="100">
I did try the following, but the slider no response.
var i = 0;
setInterval(function(){
document.querySelector('input[type=range]').value = i++;
}, 1000);
or impossible?
Upvotes: 4
Views: 12287
Reputation: 4754
you can do it with stepUp
and stepDown
functions
document.getElementById("myslider").stepUp(1);
document.getElementById("myslider").stepDown(1);
working demo : http://jsfiddle.net/dp6cwoom/
Upvotes: 4
Reputation: 1325
I found a way but not very good: to modify the style of input dynamically.
var i = 0,
oRange = document.querySelector('input[type=range]');
setInterval(function(){
oRage.value = i;
oRage.style.fontSize = i + 'px';
i++;
}, 1000);
Upvotes: 0
Reputation: 14304
<input type="range" value="0" min="0" max="100">
<script type="text/javascript"><!--
document.querySelector('input[type=range]').value = 30;
--></script>
Works ok in Safari4 (Win).
Ensure, your code is after input element or is called inside onload or similar function.
Upvotes: 2
Reputation: 55200
It should work.
document.querySelector
Its dsupported by IE8, FF3.5, Chrome1, Safari3.2 and so is input type=range
Syntax
element = document.querySelector(selectors);
Returns null if no matches are found; otherwise, it returns the first matching element.
Be careful that querySelector returns only first element of the matched ones.
So, document.querySelector('input[type=range]')
wont be as desirable as something like document.querySelector('#myrange')
Upvotes: 0