I have a slider that I want to get the step value of with jQuery. I can manually find the step value in HTML but if I change it in the future, I would prefer not to do the same in other files too.
By step value I mean step="0.05" from the slider input below:
<input id="slider" type="range" min="0" max="10" value="5" step="0.05">
CodePudding user response:
You can use attr on your slider
var step = $('#slider').attr('step')
// step will be '0.05'
an example your code working with jquery 3.5
CodePudding user response:
i'm not sure to understand the question. But with
jQuery('#slider").attr('step');
sould do the job
CodePudding user response:
use step property
$('#slider')[0].step
$('#step-value').text('STEP: ' $('#slider')[0].step);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="slider" type="range" min="0" max="10" value="5" step="0.05">
<p id="step-value"></p>
$('#step-value').text('STEP: ' $('#slider')[0].step);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input id="slider" type="range" min="0" max="10" value="5" step="0.05">
<p id="step-value">Result: </p>