Skip to content

Instantly share code, notes, and snippets.

@bolmaster2
Created September 12, 2011 07:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bolmaster2/1210774 to your computer and use it in GitHub Desktop.
Save bolmaster2/1210774 to your computer and use it in GitHub Desktop.
Show the html5 input type range values
// show the html5 input type range values
function show_ranges() {
// selector and classname on the range value
var selector = "input[type=range]",
class_name = "range-value";
// get the range values with jquery
var ranges = $(selector);
// check for support for the html5 range input and then show the value from the range
if (ranges[0] && ranges[0].type == "range") {
for (k in ranges) {
// show the value on init
show_value_from_range(ranges[k]);
// change the value on change
ranges[k].onchange = function(e) {
show_value_from_range(this);
};
}
}
// show the values in the label
function show_value_from_range(el) {
// get the elements label
var label = $('label[for='+el.id+']');
// check if the element exists - if it does: remove it
if ($("span."+class_name, label).is("*") != false) {
$("span."+class_name, label).remove();
}
// create the range element ...
var range_val_el = $('<span class="'+class_name+'">'+el.value+'</span>');
// ... and append it to the label
range_val_el.appendTo(label);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment