I would like the range to toggle itself (minimum / maximum) when I click on the label. Is that possible with only HTML or CSS ? Do I need some JS?
I have the following code :
<label>
This is the label text
<input type="range" min="0" max="1" step="0.01" value="1" />
</label>
<label>
This is the label text
<input type="range" min="0" max="1" step="0.01" value="1" />
</label>
document.addEventListener('DOMContentLoaded', function() {
var label = document.querySelector('label');
var rangeInput = document.querySelector('input[type="range"]');
label.addEventListener('click', function() {
// Toggle between min and max values
if (rangeInput.value > rangeInput.max) {
rangeInput.value = rangeInput.min;
} else {
rangeInput.value = rangeInput.max;
}
});
});