Guest User

Untitled

a guest
Jan 22nd, 2018
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // show the html5 input type range values
  2. function show_ranges() {
  3. // selector and classname on the range value
  4. var selector = "input[type=range]",
  5. class_name = "range-value";
  6.  
  7. // get the range values with jquery
  8. var ranges = $(selector);
  9.  
  10. // check for support for the html5 range input and then show the value from the range
  11. if (ranges[0] && ranges[0].type == "range") {
  12. for (k in ranges) {
  13. // show the value on init
  14. show_value_from_range(ranges[k]);
  15. // change the value on change
  16. ranges[k].onchange = function(e) {
  17. show_value_from_range(this);
  18. };
  19. }
  20. }
  21. // show the values in the label
  22. function show_value_from_range(el) {
  23. // get the elements label
  24. var label = $('label[for='+el.id+']');
  25. // check if the element exists - if it does: remove it
  26. if ($("span."+class_name, label).is("*") != false) {
  27. $("span."+class_name, label).remove();
  28. }
  29. // create the range element ...
  30. var range_val_el = $('<span class="'+class_name+'">'+el.value+'</span>');
  31. // ... and append it to the label
  32. range_val_el.appendTo(label);
  33. };
  34. };
Add Comment
Please, Sign In to add comment