Extract all data- * attributes from an element

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

How can you get all the data attributes from an element and throw them into an array?

For example, if I have a list item:

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

I would like to get all these data attributes and end up with an array or object like this (or something similar):

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

A solution in which you do not know the names of the data attributes would be preferable.

+3
source share

All Articles