jqueryrangejquery-tools

Jquery tools: Rangeinput get value on input change


I use Jquery tools rangeinput.

For example I have:

  <input id="testId" title="test" class="range" type="range" name="test" min="0" max="3000" value="15" />

And script:

$(".range").rangeinput();

        $("#testId").live('change', function() { 
            console.log($(this).data("rangeinput").getValue());    
        });

So by default my value is 15. Then I type in my input 25, but result in console is 15, than I type 20, but result is 25. What am I doing wrong?

Thank you!


Solution

  • Try it this way instead. What's happening is the changed value isn't set before you call getValue. Calling setTimeout of 0 will fix that.

    $(".range").rangeinput();
    
    $(".range").live('change', function(){
        var $range = $(this);
        setTimeout(function(){
            console.log($range.data('rangeinput').getValue());
        }, 0);
    });