Hello! I ask for help, I have already broken my whole head, the minimum skill in JQ, but as soon as I didn’t excel, the thing is that I don’t manage to change the value of ui.value by clicking on an element, that is, the slider itself moves, and the value of ui. value remains the same, I ask for your attention the code:

$( ".slider-range" ).slider({ range: "min", min: 0, max: 4, value: 2, step: 1, slide: function( event, ui ) { var steps = [0, 1, 2, 3, 4]; var step; step = ui.value; if(steps.indexOf(step)===-1) return false; if(!ui.value) { document.getElementById('message').style.display = 'none'; }else{ document.getElementById('message').style.display = 'block'; } } }); $('#five').click(function(){ $(".slider-range").slider({ value: 1 }); }); 

    2 answers 2

    You are in the click handler for a new initialize slider. Try setting the value to $(".slider-range").slider("value", 1);

     $( "#slider" ).slider({ range: 'min', min: 0, max: 4, value: 2, step: 1, slide: function(event, ui) { console.log('В обработчике slide: ' + ui.value); } }); $('#link').click(function() { $( "#slider" ).slider('value', 1); console.log('После клика по ссылке: ' + $( "#slider" ).slider('value')); }); 
     #slider { margin-top: 50px; margin-bottom: 5px; } 
     <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/themes/smoothness/jquery-ui.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script> <div id="slider"></div> <a href="#" id="link">Click me</a> 

    As you can see from the example, the value of the slider changes.

    • It does not change anything, the same thing. - Stanislav Nasonov
    • I'll write back now, look, please - Stanislav Nasonov
    • The value option generally conveys strange values - Stanislav Nasonov

    Pavel, try to derive so, their values ​​are initially different

     console.log('Параметр ui.value: ' + ui.value); console.log('Опиция value: ' + $( ".slider-range" ).slider('value')); 
    • he broke his head, asked the question himself, answered himself - and he turns to Paul O_o - Blacknife
    • The comment could not send the code, so I added the answer - Stanislav Nasonov