Home > Software design >  How do I get min and max values from a slider in jQuery?
How do I get min and max values from a slider in jQuery?

Time:12-19

I am trying to get the min and max values from my slider:

<input  data-spanid="span1" type="range" min="0" max="255" value="0">

What I've tried with jQuery:

let min = $(".slider").eq(i).min;
let max = $(".slider").eq(i).max;

If I console.log the min or max variables it returns "undefined"

let min = $(".slider").eq(i).min;
let max = $(".slider").eq(i).max;
console.log(max);
console.log(min);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input  data-spanid="span1" type="range" min="0" max="255" value="0">

CodePudding user response:

Use .prop()

let min = $(".slider").prop('min');
let max = $(".slider").prop('max');

CodePudding user response:

though your question might be duplicated here

try this

 
let min = $(".slider").attr("min");;
let max = $(".slider").attr("max");;
console.log(`max : ${max}`);
console.log(`min : ${min}`);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input  data-spanid="span1" type="range" min="0" max="255" value="0">

  • Related