KeithComito
KeithComito

Reputation: 1387

Range Input Element: Is there a way to Dynamically Change the Min Value?

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!

Upvotes: 2

Views: 3890

Answers (3)

hafichuk
hafichuk

Reputation: 10771

How about accessing the attribute directly?

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

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

Upvotes: 0

James Montagne
James Montagne

Reputation: 78630

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

should work.

http://jsfiddle.net/SNuK6/

Upvotes: 0

Rob W
Rob W

Reputation: 348972

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/

Upvotes: 3

Related Questions