Search code examples
javascriptjqueryflatpickr

get data-attribute from function


I´m trying to get the data-io attribute from my function.

<input id="42297" class="edit flatpickr-input active" data-io="in" value="14:23" type="text" readonly="readonly">

onChange: function(selectedDates, time, instance){

With this code i can get my input id threw: instance.input.id
But i cannot figure out how to access the data-ioattribute.

I´ve tried:

instance.input.data-io
instance.input.data('io')
instance.input.attr('data-io')
instance.input.attr('io')

How should i do?


Solution

  • Use instance.input.dataset.io. More information about data-* attributes here: https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes