Set jQuery slider value dynamically

14,907

Solution 1

Haven't you forget to close your if statement whith "}" ?

Edit : Have you tried something like this :

$("#slider").slider('value',50);

Solution 2

The way Pak suggested will recall the slider constructor, which will not be smooth.

The correct way, according to jQuery UI Docs , is:

$("#slider").slider('option','value',50);
Share:
14,907

Related videos on Youtube

user2298672
Author by

user2298672

Updated on June 04, 2022

Comments

  • user2298672
    user2298672 almost 2 years

    How can I set slider value dynamically? Here is my current code:

     $( "#slider-range-max" ).slider({
      range: "max",
      min: 1,
      max:61,
    
      step: 1,
      slide: function( event, ui ) {
    
        var val = ui.value;
       if(val > 10){
    
         ui.value = ui.value + 3;
    
      //   $(this).slider('option','max',500);
    
    
    }
    

    And after that this value change only once time (value bounce from 10 to 13 and to 14,15,16... after) but i need 10,13,16,19,etc. what am i doing wrond? When I try ui.value = ui.value*ui.value it works excellent (121, 144, 169, 196, etc.)

  • user2298672
    user2298672 about 11 years
    No, i've just cut part of code. And when I place ui.value = ui.value * ui.value instead of ui.value = ui.value + 3; it give me (121, 144, 169, 196, etc.) Dunno why ui.value + 3 won't work...