If I have set:
<input class="slider" type="range" min="0" max="100">
<input class="slider" type="range" min="0" max="255">
How can I use jQuery/JavaScript to get the min and max value?
I want to do something like this later, I can get the max value and parse it to a variable maxValue.
if (maxValue == 100) {console.log("100");}
else if (maxValue == 255) {console.log("255");}
Use .prop()
var minValue= $('.slider[type="range"]').prop('min');
var maxValue = $('.slider[type="range"]').prop('max');
For an array of maximum values, simply access the max property of the element:
var maxValues = $('input.slider').map(function(){
return this.max;
}).get();
// ['255', '255']
JS Fiddle demo.
Obviously, to find the max of a specific element, use a specific selector.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With