开发者

Retrieve all data-* attributes from an element [duplicate]

开发者 https://www.devze.com 2023-03-03 04:23 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Get list of data-* attributes using javascript / jQuery
This question already has answers here: Closed 11 years ago.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号