Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
40
rated 0 times [  42] [ 2]  / answers: 1 / hits: 15328  / 7 Years ago, fri, may 19, 2017, 12:00:00

How to trigger an event or detect the end of onchange event for input type range.



$('.slider').on('change',function(e){
console.log(e.target.value);
});


Now this will return a number of console logs when I start dragging the range input. I wanted to get the value at the end of onchange event. How to achieve this ?



Thank you ;)


More From » jquery

 Answers
28

Hey Gururaj you can try debounce function. It delays the firing of your event handler so you can get your input value at the end of onchange event as you want it. Lodash has a implementation of the debounce function you can use.



$range.on('change', _.debounce(function() {
$display.text($(this).val());
}, 250));


Here's a little demo for you.


[#57728] Wednesday, May 17, 2017, 7 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
daren

Total Points: 577
Total Questions: 114
Total Answers: 120

Location: Malaysia
Member since Fri, Dec 3, 2021
3 Years ago
;