So I created a Slider which displays it's value to a label as you can see below.
I want to add the option to change the slider value (position) with the label, so I made the label editable with contenteditable="true" - Now to change the value of the slider with my value in the label I thought of something like:
Thought:
$('#cv_slider').on('input', function () {
//function
})
I can get the value in my console for the function: console.log($(this).html())
But all my tries to apply it to my slider failed, maybe it's because I started JS recently..
HTML:
<div class="range-slider">
<input id="CV_SP1" class="range-slider__range" type="range" value="0.4" min="0.1" max="1" step="0.05">
<label contenteditable="true" id="cv_slider" class="range-slider__value">0</label>
</div>
JS:
var rangeSlider = function() {
var slider = $('.range-slider'),
range = $('.range-slider__range'),
value = $('.range-slider__value');
slider.each(function() {
value.each(function() {
var value = $(this).prev().attr('value');
$(this).html(value * 100 + 'mm');
});
range.on('input', function() {
$(this).next(value).html(this.value * 100 + 'mm');
});
});
};
rangeSlider();