Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get html range input type's max value through javascript?

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");}
like image 658
the_summer_bee Avatar asked Oct 25 '25 14:10

the_summer_bee


2 Answers

Use .prop()

var minValue= $('.slider[type="range"]').prop('min');
var maxValue = $('.slider[type="range"]').prop('max');
like image 140
Tushar Gupta - curioustushar Avatar answered Oct 28 '25 04:10

Tushar Gupta - curioustushar


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.

like image 21
David Thomas Avatar answered Oct 28 '25 03:10

David Thomas