Search code examples
javascriptjqueryjquery-uiuislider

jQuery UI Slider: access options from function associated with the slide event


I have a slider defined in this way:

$( "#myslider").slider({
    range: true,
    min: min_val,
    max: max_val,
    values: [ min_val, max_val ],
    slide: function(event, ui){
        $('#input_min').val(ui.values[0]);
        $('#input_max').val(ui.values[1]);
    },
});

Where min_val and max_val can change.

Now let's say that in the function associated with the slide event I want to check if the current min and max values are different from the initial ones.

I know I can access the current values with ui.values and I can get the initial min and max with the following code:

var inital_min = $( "#myslider").slider("option", "min");
var inital_max = $( "#myslider").slider("option", "max");

but this looks dumb to me, because I already have the ui object from the callback.

I tried to navigate the object with firebug but I could not locate what I'm looking for.

So, is there any other way to get these values?


Solution

  • You could just use this to access it. I put it fiddle for you.

    http://jsfiddle.net/dhQk/vr2Mg/

    var i_max = $(this).slider('option', 'max');
    var i_min = $(this).slider('option', 'min');
    

    Unfortunately no local object will have it according to the official references. http://api.jqueryui.com/slider/#event-slide