Search code examples
javascriptjquerysliderjquery-ui-sliderion-range-slider

How do I get the name of the slider in the callback function of the jquery ionrangeslider?


The example script:

<input type="text" class="js-range-slider" name="sliderNo1" />
<input type="text" class="js-range-slider" name="sliderNo2" />
<input type="text" class="js-range-slider" name="sliderNo3" />


$(".js-range-slider").ionRangeSlider({
    skin:"big",
    min:"0",
    max:"10", 
    placeholder:"none",
    hide_min_max:"true",

    onChange: function(data) {
      console.log('name of this active slider: ');
    }

});

I would like to read the name of the active slider in the callback function. How can I get this attribute at this point?


Solution

  • Use data.input[0].name to get the active slider name like this.

    $(".js-range-slider").ionRangeSlider({
        skin:"big",
        min:"0",
        max:"10", 
        placeholder:"none",
        hide_min_max:"true",
    
        onChange: function(data) {   
          console.log('name of this active slider: ' + data.input[0].name);
        }
    
    });
    

    I hope it helps you.