0

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?

Shenya
  • 334
  • 1
  • 3
  • 14

1 Answers1

2

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.

Sapikelio
  • 2,594
  • 2
  • 16
  • 40
  • Thank you very much for this. How do I get the associated index of the (.js-range-slider) class from the slider? That would also be nice to find out. I would also need that at various points. – Shenya Feb 07 '20 at 13:41
  • If you want to get the active `.js-range-slider` you can get it using attribute selector like this `$(".js-range-slider[name='"+data.input[0].name+"']")`. Is it what do you want? – Sapikelio Feb 07 '20 at 13:59
  • 1
    I was looking for exactly that: `var obj = $ (". js-range-slider [name = '" + data.input [0] .name + "']");        console.log ($ ( '. js-range slider') index (obj).);` Thank you very much for your effort. – Shenya Feb 07 '20 at 16:28
  • You're welcome. Mark my answer as solved if it worked for you. Thank you :) – Sapikelio Feb 10 '20 at 09:54