andreruffert / rangeslider.js

🎚 HTML5 input range slider element jQuery polyfill
https://rangeslider.js.org
MIT License
2.17k stars 401 forks source link

[Question] add identifiers for .rangeslider div #223

Closed rogervila closed 8 years ago

rogervila commented 8 years ago

Hello,

I want to show/hide different sliders with some checkbox that act as a toggle.

Now I'm accessing the div.rangeslider by its parent with jQuery, but if I have to change the layout, I will have to rewrite this part of the code.

I would like to be able to pass an identifier (maybe a data attribute, or an id) to every rangeslider div.

is it possible to do this?

Thank you.

andreruffert commented 8 years ago

Every instance has actually an id="js-rangeslider-{{n}}" attribute.

// Get a nodelist of all rangeslider.js instances
document.querySelectorAll('[id^="js-rangeslider"]')

To set an additional data attribute you could use the onInit fn e.g.

  $('input[type=range]').rangeslider({
    polyfill: false,
    onInit: function() {
      this.$range[0].setAttribute('your-attribute', 'your-value');
    }
  });
rogervila commented 8 years ago

amazing, this is what I was looking for.

Thank you and congratulations for the plugin!

andreruffert commented 8 years ago

✨