-2

I want the current value of a jQuery <input type='range'> to be displayed within the slider's thumb, something like this:

example
I have seen it is possible but I'm not sure where to start with coding it.

ashleedawg
  • 20,365
  • 9
  • 72
  • 105
  • Welcome to StackOverflow! It's a little difficult to understand exactly what you're trying to accomplish, so in order for us to help you better, please update your question so that it adds a little **context** to help clarify your **intent**. It would also be helpful if you could let us know what you have [**tried so far**](http://meta.stackoverflow.com/questions/261592). For further information, please refer to the help article regarding [**how to ask good questions**](http://stackoverflow.com/help/how-to-ask), and take the [**tour of the site**](http://stackoverflow.com/tour) :) – Obsidian Age Feb 08 '18 at 01:52
  • Updated question with an example for better understanding. – Krisjanis Lejejs Feb 08 '18 at 01:59
  • I am betting it was not an HTML5 range input – epascarello Feb 08 '18 at 02:01
  • What kind then? – Krisjanis Lejejs Feb 08 '18 at 02:02
  • plenty of libraries that implement sliders/ranges out there. – epascarello Feb 08 '18 at 02:04
  • Could you provide an example? – Krisjanis Lejejs Feb 08 '18 at 02:14
  • https://jqueryui.com/slider/#custom-handle – DCR Feb 08 '18 at 02:24

1 Answers1

2

$(function() {
  var handle = $("#custom-handle");
  $("#slider").slider({
    create: function() {
      handle.text($(this).slider("value"));
    },
    slide: function(event, ui) {
      handle.text(ui.value);
    }
  });
});
body {
  font-family: Arial, Helvetica, sans-serif;
}

#custom-handle {
  width: 3em;
  height: 1.6em;
  top: 50%;
  margin-top: -.8em;
  text-align: center;
  line-height: 1.6em;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>

<div id="slider">
  <div id="custom-handle" class="ui-slider-handle"></div>
</div>
ashleedawg
  • 20,365
  • 9
  • 72
  • 105
DCR
  • 14,737
  • 12
  • 52
  • 115