3

Possible Duplicate:
Get list of data-* attributes using javascript / jQuery

How would you go about retrieving all the data attributes from an element, and throw them into an array?

For example, if I have a list element:

<li id="the_example" class="haz_data" data-foo="omega" data-bar="zeta" data-derp="psi">Hello, world!</li>

I'd love to be able to grab all those data attributes and end up with an array or object like this (or something similar):

[{foo:omega},{bar:zeta},{derp:psi}]

A solution where you don't know the data attribute names would be preferred.

Community
  • 1
  • 1
hookedonwinter
  • 12,436
  • 19
  • 61
  • 74