Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Instantly Update Range Value with jQuery

I have a range, and I want to update the span that displays its numeral value instantly. The code that I have works, but only displays numeral value when you stop holding the left click down.

Here's what I have:

$("#length").change(function(){  // when range is altered, execute function
    len = $("#length").val(); // set variable "len" to the numeral value of range
    $("#password-length").html(len); // set "len" (numeral value) to a span
});

Fiddle.

like image 856
Matthew Avatar asked Dec 09 '25 07:12

Matthew


1 Answers

You could check for both the input and change events to achieve this.

In this case:

$("#length").on('input change', function(){
   $("#password-length").html(this.value);
});

jsFiddle here

like image 158
dsgriffin Avatar answered Dec 10 '25 21:12

dsgriffin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!