简体   繁体   中英

How do I get min and max values from a slider in jQuery?

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

<input class="slider" 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 class="slider" data-spanid="span1" type="range" min="0" max="255" value="0">

Use .prop()

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

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 class="slider" data-spanid="span1" type="range" min="0" max="255" value="0">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM