Retrieve all data-* attributes from an element [duplicate]
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 thos开发者_高级运维e 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.
Make a nice Javascript attay and then use jquery to convert the array
http://api.jquery.com/serializeArray/
or
http://www.google.co.uk/search?sourceid=chrome&ie=UTF-8&q=asp+json+dday#hl=en&pq=asp%20json&xhr=t&q=jquery+array+to+json&cp=15&pf=p&sclient=psy&source=hp&aq=0&aqi=&aql=&oq=jquery+array+to&pbx=1&fp=a19d57c9b1bb4a83
精彩评论