0

Hi I'm trying to add a label to the range slider I had tried using options but it is not working.

  1. How can I make range value 100% it is showing an overall 4% because of Max="4" i want to increase 25% every slide and make it 100% in 4 steps Can anyone suggest to me how do I add a label to the range slide.

var slider = document.querySelector('#slider');

function range_change_event() {
  var percent = slider.value;
  lbl.textContent = percent + '%';
}
slider.addEventListener('input', range_change_event);
<input id="slider" type="range" min="1" max="4" step="0" list="volsettings" />
<label id="lbl" id="value" for="slider">0%</label>
<datalist id="volsettings">
  <option>0</option>
  <option>1</option>
  <option>2</option>
  <option>3</option>
  </datalist>
</div>

Trying to achieve desire output enter image description here

2

1 Answer 1

1

¿something like this?

<div style="width: 300px">
  <input style="width: 100%;" id="slider" type="range" min="0" max="100" step="25" />
  <div style="width: 100%; display: inline-block; padding-left: 8px;">
    <div style="display: inline-block;  width:24%; float:left;">|</div>
    <div style="display: inline-block;  width:24%; float:left;">|</div>
    <div style="display: inline-block;  width:24%; float:left;">|</div>
    <div style="display: inline-block;  width:24%; float:left;">|</div>
    <div style="display: inline-block;  float: left;">|</div>
  </div>
  <div style="width: 100%; display: inline-block; padding-left: 5px;">
    <div style="display: inline-block;  width:24%; float:left;">0</div>
    <div style="display: inline-block;  width:24%; float:left;">1</div>
    <div style="display: inline-block;  width:24%; float:left;">2</div>
    <div style="display: inline-block;  width:24%; float:left;">3</div>
    <div style="display: inline-block;  float: left;">4</div>
  </div>
</div>

<label id="lbl" id="value" for="slider" list="volsettings"></label>
<br />
<label id="lbl2" id="value" for="slider" list="volsettings"></label>



<script>
  var slider = document.querySelector('#slider');
  range_change_event();

  function range_change_event() {
    var percent = slider.value;
    lbl2.textContent = (percent / 25);
    lbl.textContent = percent + '%';
  }
  slider.addEventListener('input', range_change_event);
</script>

Sign up to request clarification or add additional context in comments.

4 Comments

@Rubén González I added but not working can you add the snippet of your code.
@Husna I have added the snippet, I hope it's what you need
@Rubén González it is working fine. how can we label to the range slide
@Husna i have modified the code to add the labels. I am not very proud of the css but maybe it works for you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.