mardi 4 août 2015

jQuery data() value conversion

I like the fact that $('element').data() converts values to integer, float, array etc.

If I use the dataset property I only get strings.

But the problem is that jQuery.data does not update the values if I alter the data attributes on the element.

Can I use dataset but also be able to convert the values like jQuery.data() does ?

For example data-num="5" should be integer, data-bool="false" should be boolean, data-arr="[1,2]" should be array etc.

Aucun commentaire:

Enregistrer un commentaire