Skip to content

JQuery-drag range slider - widget to select a range of numbers


Notifications You must be signed in to change notification settings


Folders and files

Last commit message
Last commit date

Latest commit



27 Commits

Repository files navigation

Range slider

A small widget that allows the user to select a contiguous range of whole numbers using a slider. Check out this site for a demo. The page minimal.html constitutes a minimal working example:

   <!-- Dependencies -->
   <script src=""></script>

   <!-- Range slider code -->
   <script src=""></script>

   <!-- Range slider style -->
   <link href="" rel="stylesheet">

   <style type="text/css">
       #slider-container {
           position: relative;
           background-color: #eeeef5;

<div id="slider-container"></div>
<script type="text/javascript">
   var slider = createD3RangeSlider(0, 100, "#slider-container");


This creates a slider that spans the range from 0 - 100 (both inclusive) and adds it to the container-div. If you want diffent placements of the handles or background colors, the supplied CSS can easily be adapted. A couple of functions are defined on the slider object:

slider.range() returns the currently selected range as an {begin: number, end: number}-object.

slider.range(s,b) sets the range to span the interval from s to b (both included). If s>b the two numbers are swapped. If s or b are outside the range limits specified in the call to createD3Rangeslider a warning is printed in the console, and the values are clamped to the valid range limits.

slider.range(s) moves the range without changing its width and so it starts at s. If the move causes the range to go outside the range limits a warning is printed in the console and the range moved back to the limit.

slider.onChange(callback) adds a change-listener to the slider, so any UI modification or call to range triggers a call to callback with a single {begin: number, end: number}-argument that reflects the newly updated range.

This example illustrates the use of these functions

// Create slider spanning the range from 0 to 10
var slider = createD3RangeSlider(0, 10, "#slider-container");

// Range changes to 3-6

// Listener gets added

// Range changes to 7-10
// Warning is printed that you attempted to set a range (8-11) outside the limits (0-10)
// "{begin: 7, end: 10}" is printed in the console because of the listener

// Access currently set range
var curRange = slider.range();

// "7-10" is written to the current position in the document
document.write(curRange.begin + "-" + curRange.end);


JQuery-drag range slider - widget to select a range of numbers







No releases published