2

I am working on a page using only html5 and jquery, and I have a range input as follows:

<input id="mySlider" type="range" class="test" min="2" max="32" step="2" value="10" />

Is there any way to dynamically alter the min of this input? I've tried referencing / setting by using getElementByID and trying to access the min attribute (the same way you could do for .value), but this doesn't appear to work. Thanks!

3 Answers 3

3

I have successfully changed the value in many ways, including:

document.getElementById('mySlider').min = 5; // Example: min value of 5
$('#mySlider').prop('min', 5);               //jQuery method

Make sure that you have spelled document.getElementById correctly, using a lowercase d.

Go try this fiddle: http://jsfiddle.net/8W7FF/

Sign up to request clarification or add additional context in comments.

9 Comments

+1 for using the correct method .prop over the acceptable but oh so wrong and confusing .attr
Hmm; it doesn't work for me: in my code I have: alert(document.getElementById('mySlider').value); alert(document.getElementById('mySlider').min); and the first alert is 10 and the second is undefined?
@user201926 Use the fiddle. Does it produce the right results? If yes, the issue is caused by something else at your code. What browser are you using?
I don't see a slider on the fiddle?
Yeah; that's it. Well, you answered the stated question so I guess we can call this a case closed. Thanks!
|
0
$("#mySlider").attr("min",12);

should work.

http://jsfiddle.net/SNuK6/

Comments

0

How about accessing the attribute directly?

$("#mySlider").attr("min", 4);

See http://api.jquery.com/attr/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.